Problems with Sessions differing from page to page
Okay,
So I have my sessions set up on my website and I am having some very strange problems, I have spent about 2 days trying to find the answer to no avail.
So I have my index.php, when you go to this website the sessions work correctly, from here it checks if you are logged in (session is set), if you are, it will move you to another screen, and will use ajax queries to update the page.
If you are not logged in, it will popup a smaller window (login box), when you login the smaller window will call its creator window, saying the user has correctly logged in, and sets the session. To the problem:
The session works on: index.php, ajax_request.php (when it is called via ajax from index.php), popup_window.php (when it is popped up from index.php).
The session does not work: Any other time, this includes, php files in the same directory as index.php, this even includes ajax_request.php and popup_window.php when they are not called from index.php
** note that popup_window.php uses openid for login, it is redirected to an openid provider, then redirected back (I don't think this would matter though?).
In order to debug this, I have setup custom session handlers that insert sessions 开发者_如何学JAVAinto a mysql db, after doing this, I have noticed that it is creating separate session's and sessionid's for these different scenarios. I am very confused by this? As far as I am aware all the session options are set to default, unless my webhost has done something funky?
Why would my application be creating separate sessions all the time and not keeping the same for the same user? Sessions are the same across multiple tabs right?
I do initiate session_start(); in every page instance. I have tried playing around with 'ini_set("session.use_cookies", 1);' and 'session_set_cookie_params (0, "/", "www.domain.com");'
I can have the exact same code in index.php and test.php, have them in the same directory, and yet they still have different sessions?
Any help would be greatly appreciated!
Thanks, Josh
If you're using Apache you can do a rewrite to have domain.com redirect to www.domain.com.
here is how you can get started by modifying your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=302,NE,L]
Some explaination of the flags:
'[NC]' = ignore case
'R=302' = give a response status of 302
'NE' = Don't encode the url parameter (this is optional if you are having problems with apache double-encoding your url string)
So I had some suspicions, so I ran a bunch of tests, and as it turns out, PHP considers a domain http://www.domain.com to be different to http://domain.com, storing separate session vars for each.
Is there any way I can force all links and everything on my domain to be one or the other?
精彩评论