Jump to content

Maintaining Sessions In Php


crippen

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by crippen
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...