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
https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/
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
https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/#findComment-209326
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
https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/#findComment-209328
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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