views:

482

answers:

2

Using Google Chrome, I'm seemingly losing/corrupting session data when navigating between pages (PHP 5.0.4, Apache 2.0.54). The website works perfectly fine in IE7/8, Firefox, Safari & Opera. The issue is only with Google Chrome.

I narrowed down the problem. I'm using search friendly URL's, and hiding my front controller (index.php) via a .htaccess file. So the URL looks like: www.domain.com/blah/blah/ Here's the .htaccess file contents:

Options +FollowSymlinks 
RewriteEngine on
#allow cool urls 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*) index.php [L] 
#allow to have Url without index.php 

If I remove the .htaccess file, and expose the front controller in the URL: www.domain.com/index.php/blah/blah/, Chrome works perfectly fine.

Any thoughts ideas? I'm thinking it's some kind of problem with how Chrome identifies what cookie to use and send to the server? This happens in Chrome 4 & 5. Thanks!

A: 

Try using;

 session_set_cookie_params(0, '/', '.domain.com');

to enforce the session cookie params. Remove the prefixed period if you are enforcing 'no www', or aren't using subdomains.

You can also try calling session_write_close() at the end of the script to force PHP to write and close the session then and there (this is especially handy when you run redirect headers right after writing session data).

UPDATE:

Try using this in your .htaccess;

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
TheDeadMedic
@TheDeadMedic: Thanks for the response. I'm already doing both of the items you suggested.
Toby
Check my revised answer, let me know how it goes
TheDeadMedic
When I used your htaccess, it wasn't rewriting my particular SEF urls correctly. However, I did find an alternate htaccess file bundled with the latest version of the framework I'm using...and everything is working great now! `#<IfModule mod_rewrite.c>Options +FollowSymlinks`RewriteEngine onRewriteCond %{REQUEST_URI} !^/.*(themes|wysiwyg|images|js)/RewriteRule ^favicon.ico$ favicon.ico [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-lRewriteRule .* index.php#</IfModule>`
Toby
Glad to hear you fixed it!
TheDeadMedic
A: 

Turns out the issue was with the contents of my .htaccess file. This resolved the issue:

#<IfModule mod_rewrite.c>

############################################
## enable rewrites

    Options +FollowSymlinks
    RewriteEngine on

############################################
## always send 404 on missing files in these folders

    RewriteCond %{REQUEST_URI} !^/.*(themes|wysiwyg|images|js)/

############################################
## always send 404 on missing favicon

    RewriteRule ^favicon.ico$ favicon.ico [L]

############################################
## never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php

    RewriteRule .* index.php

#</IfModule>
Toby