HOW TO PASS VARIABLE TO NEXT PAGE IN PHP?

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
PHP
 1168  View(s)
Ratings:
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. lois waisbrooker

    Post:70

    Points:494
    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.

    Session:

    //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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!