Amster Posted October 16, 2012 Share Posted October 16, 2012 (edited) I am using the php-login script. Everything has been working fine but suddenly now when I try logging in with an account (called user1) that has always worked previously, it simply redirects me to the login page. It does not error, it just redirects. Although if I try another account (user 2), I login normally but this one account (user 1) just does not seem to not want to login and just keeps redirecting me back when I try logging in. Also, the script only works if I have the "Remember Me" box checked. I have a feeling that it is an issue with cookies, I have taken a code snippet here: session_start(); session_regenerate_id (true); //prevent against session fixation attacks. // this sets variables in the session $_SESSION['user_id']= $id; $_SESSION['user_name'] = $full_name; $_SESSION['user_level'] = $user_level; $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']); //update the timestamp and key for cookie $stamp = time(); $ckey = GenKey(); mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'") or die(mysql_error()); //set a cookie if(isset($_POST['remember'])){ setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*365, "/"); setcookie("user_key", sha1($ckey), time()+60*60*24*365, "/"); setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*365, "/"); } header("Location: myaccount.php"); Although, it may be other things. For further reference, the script I am using is from here: http://php-login-script.com Thanks! Edited October 16, 2012 by Amster Quote Link to comment https://forums.phpfreaks.com/topic/269557-help-with-login-script/ Share on other sites More sharing options...
White_Lily Posted October 17, 2012 Share Posted October 17, 2012 (edited) You say it just redirects you to login page with no errors... Try commenting out all header() lines, and put error messages in their place instead. Then post back here and tell us what the error is. //error message echo "Error: ".mysql_error(); Edited October 17, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/269557-help-with-login-script/#findComment-1385720 Share on other sites More sharing options...
Christian F. Posted October 17, 2012 Share Posted October 17, 2012 You have no code to validate the login information, or set the user data in the session, in the snippet above. Either you've removed way too much from your code, or that is your problem. Quote Link to comment https://forums.phpfreaks.com/topic/269557-help-with-login-script/#findComment-1385796 Share on other sites More sharing options...
Pikachu2000 Posted October 17, 2012 Share Posted October 17, 2012 (edited) In the posted code, the header() is unconditional; it will redirect regardless of what happens elsewhere in the script. An exception may be if an error message is generated. If that is happening, the header() call would generate a 'headers already sent' error instead of redirecting. Edited October 17, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/269557-help-with-login-script/#findComment-1385840 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.