jd2007 Posted July 22, 2007 Share Posted July 22, 2007 How to create the section on login forms which lets users log in forever ?...is it done usig cookies...i create my login systems with sessions... Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 I create my logins system with sessions too, but when you need the system to remember the user, than just stick to cookies. You can create the cookie with the time limit you want: setcookie('name', 'value', expire_time) For one hour expire: setcookie('name', 'value', time()+3600) For ten days expire: setcookie('name', 'value', time()+60*60*24*10) You can set it to expire after 10 years (time()+60*60*24*365*10), so it practically is forever Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 24, 2007 Author Share Posted July 24, 2007 <?php session_start(); header("Cache-control: private"); if ($_POST["login_username"]&&$_POST["login_password"]) { include("connect.php"); $querya="SELECT confirm FROM users WHERE username='$_POST[login_username]' AND password='$_POST[login_password]'"; $resulta=mysql_fetch_array(mysql_query($querya)); if ($resulta['confirm']==1) { $queryb="SELECT * FROM users WHERE username='$_POST[login_username]' AND password='$_POST[login_password]'"; $resultb=mysql_fetch_array(mysql_query($queryb)); if($resultb>0){ $_SESSION['Logged In']="true"; $_SESSION['username']=$resultb['username']; $_SESSION['password']=$resultb['password']; $_SESSION['credits']=$resultb['credits']; $_SESSION['admin']=$resultb['admin']; header("location:index.php"); } else { echo "Wrong username or password."; } } else { echo "Please click <a href='resend.php'>here</a> to resend your confirmation mail."; echo $resultb; } } else if (($_POST["login_username"]=="")&&$_POST["login_password"]) { echo "Please enter your username."; } else if ($_POST["login_username"]&&($_POST["login_password"]=="")) { echo "Please enter your password."; } else if (($_POST["login_username"]=="")&&($_POST["login_password"]=="")) { echo "Please enter your username and password."; } else {} ?> as u can see above, i use sessions, how to i modify the code above to switch to cookies... Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 24, 2007 Author Share Posted July 24, 2007 never mind, i know how to do it now Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 ok glad you found it, anyway for who doesnt know how to replace sessions with cookies in a case like this, just replace the $_SESSION['name'] = 'value' with setcookie('name', 'value', time()+3600). To request the value of a cookie, just use $_COOKIE['name']. And you dont need to use session_start() anymore. 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.