Hi all I have 2 php scripts. page1.php and page 2.php On page1.php i have 2 variables. $var1 and $var2. If u submit page1.php i am redirecting the page to page2.php using header "location:page2.php"; exit();
How can i access the $var1 and $var2 on page2.php Will it not post the values of the variables to page2.php automatically, so that i can use it.
Thanks IM
header ("location: page2.php?var1=".$var1."&var2=".$var2;
but, this will show the values of the variable in the url. Is there any way i can post these variables to the next page without showing it in the url. I have around 10 variables to pass to next page.
Thanks
i have no idea, if so can be done, inform me if you find a solution,
Use cookies. At the end of page1.php, before your header (), do this:
setcookie ("var1", $var1); setcookie ("var2", $var2);
And at the start of page2.php, do this:
$var1 = $COOKIE['var1']; $var2 = $COOKIE['var2'];
Appart from cookies you can use sessions, but Cookies are best on the go. Rohun Hill's answer can't be better.
Originally posted by AlexP Appart from cookies you can use sessions, but Cookies are best on the go. Rohun Hill's answer can't be better. ------
Alex,
I am just curious as to why cookies are his best bet as opposed to sessions. Not that I am challening your recommendation. I would do the same. I just want to know WHY you say that. I am still learning about proper usage of sessions and every bit helps.
Thanks!
I agress that cookies are really not the best place to store information. PHP session mechanism imply setting a cookie to store the PHP session identifier. Though if cookies are not enabled, PHP will automatically append the session id to links and to forms using an hidden field. So either you use session to store your data or you use script to submit your form.
<form name="dataForm" method="post" ...> </form> <script type="text/javascript"> <!-- dataForm.submit( ); //--> </script>