Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session data lost in Chrome only

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.

EDIT:

Problem resolved by switching from SESSIONS TO COOKIES...

like image 722
Mathieu Dumoulin Avatar asked Nov 23 '11 19:11

Mathieu Dumoulin


People also ask

Where is session data stored Chrome?

Chrome Session Data is stored in the 'Sessions' folder within the 'Session' and 'Tabs' files. Chrome Thumbnails are stored in the 'Top Sites' SQLite database, within the 'thumbnails' table. Older versions of Chrome stored Thumbnails in a 'Thumbnails' SQLite database, within the 'thumbnails' table.

How do I retrieve session data?

Accessing Session Data: Data stored in sessions can be easily accessed by firstly calling session_start() and then by passing the corresponding key to the $_SESSION associative array. session_start();

Where is session data saved?

The session data that you read and write using $_SESSION is stored on server side, usually in text files in a temporary directory.

Can you view session variables in Chrome?

No, you cannot view session state variables at client side. Session state is stored at server, and Client browser only knows SessionID which is stored in cookie or URL. Sessions are identified by a unique identifier that can be read by using the SessionID property.


10 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.

like image 162
Ben Avatar answered Oct 04 '22 20:10

Ben


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.

like image 44
user1665622 Avatar answered Oct 04 '22 21:10

user1665622


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.

like image 37
Camilo Avatar answered Oct 04 '22 19:10

Camilo


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.

like image 32
Kash Avatar answered Oct 04 '22 21:10

Kash


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.

like image 33
user2246924 Avatar answered Oct 04 '22 21:10

user2246924


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

like image 35
sijo vijayan Avatar answered Oct 04 '22 21:10

sijo vijayan


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

session_id($_GET['sid']);
session_write_close();
like image 39
rota Avatar answered Oct 04 '22 21:10

rota


I solved the problem by removing the line:

base href="http://mysite/"

from the head tag in the HTML code.

like image 20
Rafael Alves Avatar answered Oct 04 '22 19:10

Rafael Alves


Looking on the following link: http://code.google.com/p/chromium/issues/detail?id=45582

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;
 }
like image 27
kornstar11 Avatar answered Oct 04 '22 21:10

kornstar11


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

like image 21
Matt Avatar answered Oct 04 '22 19:10

Matt