dflow Posted January 18, 2012 Share Posted January 18, 2012 i'm redirecting: but my session is destroyed. i tried to use session_write_close(); to maintain , but nada. the page is redirected blank session_write_close(); $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $params = $_SERVER['QUERY_STRING']; $currentUrl = $protocol . '://' . $host . $script; if ($host<>'example.com'){ session_write_close(); header("Location: https://www.example2222.com"); } else{} Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/ Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 Are you going from http to https? You can't keep cookies between the two. Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1308967 Share on other sites More sharing options...
ManiacDan Posted January 18, 2012 Share Posted January 18, 2012 You must die() after a header call. Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309018 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 You must die() after a header call. Why? Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309043 Share on other sites More sharing options...
ManiacDan Posted January 18, 2012 Share Posted January 18, 2012 Because otherwise sessions don't work right ;-) Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309052 Share on other sites More sharing options...
scootstah Posted January 19, 2012 Share Posted January 19, 2012 Because otherwise sessions don't work right ;-) Can you elaborate? Wouldn't the script end after the header redirect anyway? Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309138 Share on other sites More sharing options...
dflow Posted January 19, 2012 Author Share Posted January 19, 2012 i didn't notice i created a new word Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309221 Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 Scripts do not end after header redirects, so open connections are not closed and sessions are not written and closed. If you want the script to end, you have to die(). Header() is used for more than just redirects, it doesn't automatically die. Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309225 Share on other sites More sharing options...
scootstah Posted January 19, 2012 Share Posted January 19, 2012 Header() is used for more than just redirects, it doesn't automatically die. I know that, I just thought that since it was a redirect that it would do it then and not later. I just tested it and it seems you are right. Good to know. Quote Link to comment https://forums.phpfreaks.com/topic/255305-maintaing-session/#findComment-1309256 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.