Session variables are not persisting between page loads

前端 未结 11 1413
梦谈多话
梦谈多话 2020-12-10 11:12

Can someone tell me why the session vars are not passing between pages? They were working up to 2 days ago. Now its not? There is a third party system that logs users in b

相关标签:
11条回答
  • 2020-12-10 11:25

    You did not call session_write_close()

    0 讨论(0)
  • 2020-12-10 11:27

    As already mentioned, ensure you're calling session_start() on each page.

    Additionally, are the scripts on different subdomains?? If they are you should set the INI value session.cookie_domain to .DOMAIN.EXT.

    To further debug this whole situation, do some simple cookie watching. See if PHPSESSID is present as a cookie on both page requests, if it's not then this is your problem. You can't store cookies cross-domain unless you reconstruct them.


    In response to your update, try doing this underneath your call to session_start():

    echo session_id();
    

    Confirm that it's the same on both pages. If not, check the value of session.cookie_domain like this:

    echo ini_get('session.cookie_domain');
    

    Is that set to anything? By default it should be blank, if it's set, especially not to your domain, this is the problem.

    You can also try debugging the cookie value of PHPSESSID like I first suggested.

    0 讨论(0)
  • 2020-12-10 11:29

    it's not the hosting server issue...

    check your URLs

    if a user is login under "example.com" session will be stored for "example.com" and not "WWW.example.com" so if a link goes to www.example.com it will not have that session.

    you can use htaccess to always set the url to "WWW.example.com" use below code for it

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^hemantjadhav.com$ [NC]

    RewriteRule ^(.*)$ http://www.hemantjadhav.com/$1 [L,R=301]

    (replace hemantjadhav with your domain name)

    0 讨论(0)
  • 2020-12-10 11:31

    Check List
    1. Make sure that you have used session_start(); in the next page.

    2. Are you using .htaccess file?
        if so remove the .htaccess file and check the same.
        some time rewrite rules cause session probs...

    3. If session is working fine and you have trouble only with token, then check the token sent in url is url_encoded.

    0 讨论(0)
  • 2020-12-10 11:35

    I would add that I got caught up with the same problem, except that in my case page was behind Varnish caching proxy and I missed out that configuration had a line where cookies were allowed only on specific paths, otherwise they would get removed with the following directive:

    unset req.http.cookie;

    Dont forget to also check your proxy settings.

    0 讨论(0)
提交回复
热议问题