Send data to another page

Asked

Viewed 797 times

-1

There is some way to send php data through the POST; the same way it is done through the Teg form action.

That is, send data from page A to B and be directed to page B accessing this data.

  • Be directed? What did you mean by that?

  • Let’s assume that I have a variable on screen A and when I click on a button I am directed to atela B.But I need a variable in B that is in A . I know some ways to do this via GET by passing the variable through the URL or cookies.My question is whether to do by POST?

  • Pages A and B are in the same domain?

  • yes. They are inside the same folder.

  • the behavior I want is the same one obtained with form action.

  • So the answer is: it won’t be possible. Why do you need to do this? It’s looking like an XY problem to me.

  • It was a question.So the way to do this is through the URL by get or using cookies/session.

  • 1

    Impossible to say without knowing the problem you are solving. Research more about the HTTP protocol and about it not having state. Depending on the problem, there may be many other better ways to solve.

Show 3 more comments

2 answers

1


You can use a full Hidden form:

Page A:

<b>Variável AA:</b>: <?= $aa ?><br />
<b>Variável AB:</b>: <?= $ab ?><br />
<form action="paginaB.php" method="post">
   <input type="hidden" name="variavel_aa value="<?= $aa ?>">
   <input type="hidden" name="variavel_ab value="<?= $ab ?>">
   <input type="submit" value="PROXIMA">
</form>

Page B:

<b>Variável AA:</b>: <?= $POST['variavel_aa'] ?><br />
<b>Variável AB:</b>: <?= $POST['variavel_aa'] ?><br />
  • But in this case it will not be PHP that will make the request; it will be the browser itself, after handling the response of page A.

  • Yes, I would use $_SESSION, but he said "the same way it’s done through the Teg form action"

1

You can do that with session variables. On page A:

$_SESSION['variavel'] = 'Valor da variavel';

On page B you capture the value passed:

$var = $_SESSION['variavel'];

Just one thing: at the beginning of the pages that will use this should be put the following:

session_start();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.