Home » Php » php – Session data lost in Chrome only

php – Session data lost in Chrome only

Posted by: admin April 23, 2020 Leave a comment


I have a problem similar if not identical to the problem in this thread:
Randomly Losing Session Variables Only In Google Chrome & URL Rewriting

But all solutions in that thread don’t work for me. I’m getting a strange behavior from only Google Chrome in my PHP/MySQL App. If I try it with Firefox, it works, but Chrome doesn’t.

I navigate to some place in my shopping cart and at several places in the code I’ll store session data. Don’t worry about me starting the session or anything related to that, I’ve got 11 years in webapp dev, all is done fine.

In all browsers, I can var_dump($_SESSION) and get my data back, but in Chrome it doesn’t keep the data. Also note that the session does get passed on, I can look in the network monitor and I see the cookie being sent and many other things related to session work but that one $_SESSION['last_viewed_element'] is not kept. I also can’t seem to set anything else, all gets lost.


Problem resolved by switching from SESSIONS TO COOKIES…

How to&Answers:

I had a very similar problem, in my case the problem was a 404 called due to a missing favicon.ico in Chrome only. The 404.php called the footer which altered the Session Variables.
I hope that helps someone.


The issue could be your server is looking for favicons, if it is not found the server throws out a 302 redirect, which kills the session variables.


I had this issue and was able to fix it. Chrome keeps looking for a .ico file and for some reason it was affecting it. Once I placed the .ico file in the root of the site everything started working. Crazy but true.


I faced same problem, but on IIS with ASP.Net MVC. IE and Firefox were doing fine, but on Chrome I was losing session data. Eventually found out that a 404 error was clearing a cookie in Chrome. Below are the steps I followed to find the problem and resolve. I suggest others to try:

  1. On Chrome, Use Tools -> Developer Tools. Refresh the page so “Developer Tools” starts showing data.

  2. On Developer tools, Check Resources -> Cookies. Right after a successful log in, I had 2 cookies for the domain I was testing. On navigating to the page where I lost session, one of the cookies did not show up anymore. The screenshot was taken after the fix, showing both cookies:
    enter image description here

  3. Now check Network tab. Look carefully for any resource (html/image/css/js/…) which has any error. I had a 404 error for a font file. The 404 error was caused by missing mime type in IIS.
    fixing the 404 error cleared the problem in Chrome. The screenshot, again taken after fix, had all resources with OK status: enter image description here

The bonus was, investigating this problem helped me find out missing mime type in IIS, which was affecting more pages on all browsers.


Had same problem and finally solved. Login set session with domain.com but in the redirect it was www.domain.com. IE and FF seem to assume www and no www are same but Chrome doesn’t. Found by checking Host in network log for each page load.


Just try this before wasting your time

If you are already logged in your webspace ( control panel / Cpanel / Plesk Panel )
in the same browser. Then logout from that control panel and clear the
cookies and try Again

In case of

session data lost in chrome only

In my case I just reset chrome browser

Go to chrome://settings/ then click advanced then reset

enter image description here


The code I was working with had the same issue. Solved by removing the following:



I solved the problem by removing the line:

base href="http://mysite/"

from the head tag in the HTML code.


Looking on the following link:

I belive the issue is with PHP getting the request that did not match a file and then not properly handling 404’s correctly. I had to tell Nginx to match any URL with favicon.ico and then return a 404.

Here is my line for Nginx:

 if ($request_uri ~ 'favicon') {
            return 404;


HA! i finally solved it!

When doing a header() redirect in PHP, you must do a die() right after it. THAT only solves it for all browsers except for Chrome.

For Chrome you also gotta do a session_write_close() right before the header()

Sweeeeeeeeet success


In your php ini file try setting

session.save_path = /path/to/your/tmp

On some servers, sometimes the session needs an explicitly direct session file to save in a local directory or otherwise some weirdness happens.


This solved my problem instantly: go to chrome://settings/cookies then locate your localhost then remove its cookies. The solution is so simple, it’s worth a try


We had the same issue yesterday the whole day.

What (seemingly) solved it (for us) was a chrome update.

We had Version 45.0.2454.93 und since the update to version 45.0.2454.99 the problem didn’t occure again …


I had similar problem, I discovered the reason which was very strange.
In my case one image url inside a css class was wrong!! The browser coudn’t load the image and because the page was a sign up form with password field, the browser reset the session for security reasons.


I am not sure if your case is similar to mine. But for me the reason was the formation of URL.

With chrome, when typing the URL as “http://www.domainname.com” and setting the session variables there.

and redirecting with “http://domainname.com” without the WWW. the sessionid is not reused.

This resolved my issue hope this is help


You are probably loosing sessions only on your development environment, and it may be most probably because of ‘same origin policy’ of Chrome. If so, then this is your solution Disable same origin policy in Chrome


I found my version of the issue was exactly as described here and here and so I want to add a further qualifier to the above that

Google Chrome (v.59, stable) Inspector does not tell you that the favicon.ico is inaccessible and does not tell you the page is 302 redirected.


After all, no answer, problem still exists, i just made a switch to using cookies instead, if anyone ever gets that problem with chrome+wordpress at the same time, dont lose more time, switch to cookies…


I found a “solution” (is not a problem but only effects!!) …
if in your page use ajax, ajax is asyncronus …
If I call a function that working on SESSION than i call another page that working on session, some times the first call is not finish before second start and effect of the first overwrite response of the second.
I resolve problem with async:false in every ajax call.

    url: '/io/resetsession.php', 
    **async: false**
    url: '/io/loaddata.php', 
    **async: false**,