How to auto-redirect to another PHP script passing along some data?
I've got a script that processes some data, does not render any text and then redirects user to final page. On the final page, user should be able to see some data. I used SESSION variable to pass it but somehow it's being lost. It looked like this
$_SESSION['ses']['field1'] = $var1;
header("Location: http://page.com/another.php");
exit;
(i have the session_start() put at the beggining of both files). Is that header redirection "losing" the s开发者_开发知识库ession id? And if this is wrong, and won't work, than what is the other way? I can only imagine using $_GET or cookies but both are less secure and easy to manipulate.
Explicitly send the session ID on the new page, like this:
session_start();
$_SESSION['ses']['field1'] = $var1;
header("Location: http://page.com/another.php?phpSESSID=".session_id());
Then in new page, GET the session ID an use it like this
<?php
session_id($_GET['phpSESSID']);
session_start();
...
This will work. It is a known PHP bug, if you are using an ancient PHP version. Also, sometimes the session is REALLY lost while redirecting, so you need to get the session ID by which you can recover your session. Some browsers work fine with redirection but some don't, like IE6.
精彩评论