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? Quote Link to comment 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"); } Quote Link to comment 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. Quote Link to comment 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." Quote Link to comment 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. Quote Link to comment 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/ 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.