1

Hi

I have problems with Google Chrome, while developing a PHP website.

I start a session, and store a flag inside it. But when I reload the page, the session value is not recognized.

What can be wrong? Thanks for reply.

session_start();
if (isset($_SESSION['chrome'])) {
  echo 'SESSION OK';
}
else {
  $_SESSION['chrome'] = 'yes';
}

This is simple code, but it doesn't work...

shkschneider
  • 17,833
  • 13
  • 59
  • 112
Filip Glazar
  • 43
  • 1
  • 8
  • So it only fails with Google Chrome?.. – shkschneider Jul 29 '12 at 18:44
  • Are you accessing the page using the same domain, what I mean by this is domain.com vs www.domain.com? – arosolino Jul 29 '12 at 18:46
  • Yes only with chrome. After F5 session stay, but after click on other url of the same page it disappear. – Filip Glazar Jul 29 '12 at 19:00
  • disappears after clicking? it looks your're changing the domain or something...can you post the url of the page and of the link you are clicking? if you have some configuration before session_start() you should post as well. – Hugo Mota Jul 29 '12 at 19:06

4 Answers4

0

I had the exact same problem with Chrome not persisting php sessions on a login system. Found the following article: https://secure.kitserve.org.uk/content/php-session-cookie-problems-google-chrome-and-internet-explorer which says:

When testing a local site in Chromium, you must either access it via IP address (e.g. 127.0.0.1) or set the cookie domain parameter to the empty string.

I hope this helps.

Alan Tyson
  • 43
  • 3
0

I had exact same problem, but on IIS and ASP.Net Mvc. An F5 would make the session recover, but moving to another page caused the problem again. I posted the answer for another SO question. Try it out and see if works.

Community
  • 1
  • 1
Kash
  • 1,118
  • 9
  • 10
0

I think the answer to this is to use session_name before session_set_cookie_params. For example...

session_name('MySession');
session_set_cookie_params( 3600*24, '/', $_SERVER['HTTP_HOST'], is_https() );
session_cache_expire(60*24); // cache expire 60 mins
Justin Vincent
  • 1,329
  • 2
  • 14
  • 22
-1

Check to see if you deactivated cookies in your browser.

Hugo Mota
  • 11,200
  • 9
  • 42
  • 60