Hi Guys,

I'm new to PHP and need help with passing variables from my form to multiple pages. I have global registers turned to off.

I am able to retrieve my form inputs on the second page.. however unable to retrieve the same on the other pages after.

for example -

form.php - my form page input - $_POST
action.php - I'm able to retrieve - $_POST

action2.php - I have a link on action.php which then redirects to this page; which again requires - $_POST but doesn't work, I tried validating and it did not return any value

Any experts out there??

You cannot access $_POST in action2.php . Its only available in action.php since it is posted from form.php to action.php . In order to make it available in action2.php (which is a hyperlink), you have to pass it in the query string like this.

echo "<a href=action2.php?startdate=".$_POST['startdate'].">Click here to go to action2.php </a>";
//You can then access startdate in action2.php as $_GET['startdate']

If you don't want to pass it in the query string, you can use sessions (But I think using sessions only for this particular variable is useless).

Or if you don't like the ugly url when using hyperlinks then use sessions. To convert $_POST to $_SESSION simply use the following at the very top of your action.php page:

foreach($_POST AS $key => $val) {

Then on every page that uses sessions, you need to place session_start(); on the second line with no output before it. And to retrieve a session use the following.

//post variable was $_POST['name']
echo $_SESSION['name'];

//post variable was $_POST['age']
echo $_SESSION['age'];


It is very easy. In order to "register" or global $var variable, you can simply call global_session('var');

In doing so, you are able to access the same value in memory by the following 3 methods:

1. $var

PHP Source Code for global_session() is,

function global_session($var){


Thanks a million guys :) it worked perfectly, I prefer to use SESSIONS though..

This question has already been answered. Start a new discussion instead.