Jump to content

Session lost in php redirect


freephoneid

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.