How to Pass variable to next page in php?

Posted by  Ankita Pandey
 1936  View(s)
Rate this:
it seems pretty simple but I can't find a good way to do it.

Say in the first page I create a variable

$myVariable = "Some text";

And the form's action for that page is "Page2.php". So in Page2.php, how can I have access to that variable? I know I can do it with sessions but I think it's too much for a simple string, and I do only need to pass a simple string (a file name).
  1. Re: How to Pass variable to next page in php?

    HTML / HTTP is stateless, in other words, what you did / saw on the previous page, is completely disconnected with the current page. Except if you use something like sessions, cookies or GET / POST variables. Sessions and cookies are quite easy to use, with session being by far more secure than cookies. More secure, but not completely secure.


    //page 1
    $_SESSION['varname'] = $var_value;
    //page 2
    $var_value = $_SESSION['varname'];

    Remember to run the session_start() statement on both these pages before you try to access the $_SESSION array, and also before any output is sent to the browser.

      Modified On Apr-06-2018 01:47:45 AM