eevan79 Posted July 24, 2010 Share Posted July 24, 2010 I am not sure if following code working. First I set cookie when user login: //SET cookie if (isset($_POST['rememberme'])) { /* Set cookie to last 1 year */ setcookie('username', $_POST['user_name'], time()+60*60*24*365, '/account', ''); setcookie('password', sha1($_POST['user_pass']), time()+60*60*24*365, '/account', ''); } else { /* Cookie expires when browser closes */ setcookie('username', $_POST['user_name'], false, '/account', ''); setcookie('password', sha1($_POST['user_pass']), false, '/account', ''); } //END cookie In always included header.php I check if this cookie exist: if(isset($_COOKIE['username']) AND isset($_COOKIE['password']) AND $_SESSION['signed_in']==false) { $result=mysql_query("SELECT * FROM ".$table_prefix."users WHERE user_name = '".$_COOKIE['username']."'"); if (mysql_num_rows($result) >=1) { $row = mysql_fetch_assoc ($result); if (sha1($row['user_pass']) == sha1($_COOKIE['password'])) { echo "signed in"; $_SESSION['signed_in'] = true; $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_name'] = $row['user_name']; $_SESSION['user_level'] = $row['user_level']; $_SESSION['user_ip'] = $_SERVER["REMOTE_ADDR"]; } } } and when user signout: setcookie('username', '', false, '/account', ''); setcookie('password', '', false, '/account', ''); I am not sure if this code working. How to check it (when session end?) ? Link to comment https://forums.phpfreaks.com/topic/208734-set-cookie-login/ Share on other sites More sharing options...
eevan79 Posted July 24, 2010 Author Share Posted July 24, 2010 Solved. Cookies didnt setup properly. setcookie('username', $_POST['user_name'], time()+60*60*24*365); setcookie('password', sha1($_POST['user_pass']), time()+60*60*24*365); Link to comment https://forums.phpfreaks.com/topic/208734-set-cookie-login/#findComment-1090497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.