freephoneid Posted November 6, 2008 Share Posted November 6, 2008 Hi, I want to redirect to other file in PHP. How can I do that? I'm using below syntax: $_SESSION['login'] = 'test'; header("Location: " . $_REQUEST['destination']); However, the redirect is working fine but it loses all session variables which I set before redirecting. In this case, I've set the session variable called login. It gets lost when I try to access it from the page where it redirected. Can anyone help me how to retain the session or is there any different way to redirect which I can try & see if the session persists? Thanks! Link to comment https://forums.phpfreaks.com/topic/131709-session-lost-in-php-redirect/ Share on other sites More sharing options...
mrMarcus Posted November 6, 2008 Share Posted November 6, 2008 can you post the other page you are trying to access the $_SESSION info from? you must have session_start(); at the top of any/every page you are accessing $_SESSION variables from. without it, you won't be able to access them. Link to comment https://forums.phpfreaks.com/topic/131709-session-lost-in-php-redirect/#findComment-684155 Share on other sites More sharing options...
freephoneid Posted November 6, 2008 Author Share Posted November 6, 2008 Hi, I do have that line in a.inc which is included in b.php as shown below: require_once("a.inc"); if (!IsLoggedIn()) { header("Location: index.php"); } But some how, session is lost..... Thanks Link to comment https://forums.phpfreaks.com/topic/131709-session-lost-in-php-redirect/#findComment-684172 Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2008 Share Posted November 7, 2008 Either sessions are not working at all, you have a header problem that is preventing the session cookie from working, or your redirect causing a change in the hostname or path that does not match the session cookie settings. Have you confirmed that sessions work by browsing directly between the two files without using a redirect? Are there any php errors in your web server error log file or have you tried turning on full php error reporting in your script to display any errors? What exactly is the full URL of the first page and the exact URL being supplied to the redirect and what are the values of session.cookie_path and session.cookie_domain? Link to comment https://forums.phpfreaks.com/topic/131709-session-lost-in-php-redirect/#findComment-684244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.