crippen Posted February 18, 2006 Share Posted February 18, 2006 I'm trying to maintain some session variables across pages in php. Does it make a difference if the variables are stored across pages wehre I go back and forth between "www" and without? What I mean is, if I store some strings into session variables using a page called "****/pagename.php", then if I link the user to "www.****/page2.php" would that cause those session variables to be lost? Quote Link to comment Share on other sites More sharing options...
surefire Posted February 19, 2006 Share Posted February 19, 2006 Shouldn't be lost. With cookies I've noticed that it really depends on how you set the cookie, and that there is a way to make it work whether www or not. php.net is a great resource on these kinds of questions. The user input is really a goldmine. Quote Link to comment Share on other sites More sharing options...
TCH-Tim Posted February 19, 2006 Share Posted February 19, 2006 Shouldn't be lost. Second that. Why, are you having problems? Quote Link to comment Share on other sites More sharing options...
crippen Posted February 19, 2006 Author Share Posted February 19, 2006 I was helping someone else with this issue. Actually the variables were being passed in the URL string in a non-www URL, and going to a URL with www, we thought that may be the problem. Just wondering if anyone here might be able to confirm if that is the case. For example, going from http--domainDotcom/file.php?col=bl&img=default&c=4&i=1 and then go to http--wwwDotdomainDotcom/file.php returns all empty strings from session vars. Quote Link to comment Share on other sites More sharing options...
crippen Posted February 20, 2006 Author Share Posted February 20, 2006 (edited) some testing around I've done proves that yes, switching to a hard-coded link to a "www" URL when you are coming from a URL that does not have "www" drops the session values. SessionID is in fact retained, but the values held in session are lost! Try it out here: renkai.com Edited February 20, 2006 by crippen Quote Link to comment Share on other sites More sharing options...
surefire Posted February 20, 2006 Share Posted February 20, 2006 A session is a type of cookie. As I said: With cookies I've noticed that it really depends on how you set the cookie, and that there is a way to make it work whether www or not. php.net is a great resource on these kinds of questions. A little research and I've solved your problem: >$url = 'yoursite.com';// leave off www and http:// !!!!!! session_set_cookie_params(0,'/', '.'.$url,''); session_start(); I have tested on my own server. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.