Pi_Mastuh Posted March 17, 2007 Share Posted March 17, 2007 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 More sharing options...
ldsmike88 Posted March 17, 2007 Share Posted March 17, 2007 For them to stay logged in you would have to use cookies to remember their session information. As for the redirecting you would do something like this: if($session){ header("location: redirectURL.php"); } Link to comment https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/#findComment-209320 Share on other sites More sharing options...
Pi_Mastuh Posted March 17, 2007 Author Share Posted March 17, 2007 How do I use the cookies? I can never get them to work with the sessions. Link to comment https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/#findComment-209321 Share on other sites More sharing options...
ldsmike88 Posted March 17, 2007 Share Posted March 17, 2007 I believe there are some good tutorials here on phpfreaks.com. If you don't like those I always run a search in google for what I'm looking for. Maybe try searching for "php cookies tutorial." Link to comment https://forums.phpfreaks.com/topic/43090-trouble-with-sessions/#findComment-209322 Share on other sites More sharing options...
Pi_Mastuh Posted March 17, 2007 Author Share Posted March 17, 2007 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 More sharing options...
ldsmike88 Posted March 17, 2007 Share Posted March 17, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.