Jump to content

Trouble with sessions


Pi_Mastuh

Recommended Posts

When a user logs in on my site it goes

session_start();

   session_register('preuserName');
   session_register('preuserID');

  $session=session_id();

 

But when the user closes the browser they have to relogin. How would I make them never expire, until the user logs out that is, and when they go to the main page (index.php) it re-directs to another page if it finds the session?

Link to comment
Share on other sites

So I set the cookie on the page that creates the session, making the cookie value the session?

 

   $cookieName="preuserName";
  $cookieVal="$_SESSION['preuserName']";
  $cookieExp=time()+(60*60*24*31);
  //All the values set, now to call the function;
  setcookie($cookieName,$cookieVal,$cookieExp);
  
  $cookieName2="preuserID";
  $cookieVal2="$_SESSION['preuserID']";
  $cookieExp2=time()+(60*60*24*31);
  //All the values set, now to call the function;
  setcookie($cookieName2,$cookieVal2,$cookieExp2);

 

How does it tell it to get the session from the cookie once the user closes the browser and goes back another time? I can't find anything on that.

Link to comment
Share on other sites

It sounds to me like you just use it like a variable. For example you could say:

$cookieVal= $_COOKIE['cookiename'];

 

That is the extent of my cookie knowledge. Here is a good article if you want it. I think the info you are looking for is near the middle/bottom of page two.

 

http://www.devarticles.com/c/a/PHP/User-identification-using-cookies-in-PHP-MySQL/

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.