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... Link to comment https://forums.phpfreaks.com/topic/61196-how-to-create-the-section-on-login-forms-which-lets-users-log-in-forever/ 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 Link to comment https://forums.phpfreaks.com/topic/61196-how-to-create-the-section-on-login-forms-which-lets-users-log-in-forever/#findComment-306036 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... Link to comment https://forums.phpfreaks.com/topic/61196-how-to-create-the-section-on-login-forms-which-lets-users-log-in-forever/#findComment-306040 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 Link to comment https://forums.phpfreaks.com/topic/61196-how-to-create-the-section-on-login-forms-which-lets-users-log-in-forever/#findComment-306043 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. Link to comment https://forums.phpfreaks.com/topic/61196-how-to-create-the-section-on-login-forms-which-lets-users-log-in-forever/#findComment-306071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.