Jump to content

Help With Login Script


Amster

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/269557-help-with-login-script/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.