my “remember me”-feature

shan9211

New Member
Finally I have got this function to work. It does its job but it looks real messy, just wanna hear your thoughts and maybe theirs something I could improve?Thanks alot!Login\[code\]$result = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."' AND password = '".md5($_POST['password'])."'");$row = mysql_fetch_object($result); if (mysql_num_rows($result) == 0) { exit('Bad Login'); } $_SESSION['id'] = mysql_result($result, 0, 'id'); # The user wants to be remembered if (isset($_POST['remember'])) { $key = md5(uniqid()); setcookie('remember', $key, time()+900000); /* expire in 10 days */ mysql_query("UPDATE users SET sessionkey = '$key' WHERE id = ".mysql_result($result, 0, 'id')); }\[/code\]And on each page I check:\[code\]if (isset($_SESSION['id'])) {header("Location: welcome.php");}elseif (isset($_COOKIE['remember'])) {$rs = mysql_query("SELECT * FROM users WHERE sessionkey = '$_COOKIE[remember]'");if (mysql_num_rows($rs) == 1) { $_SESSION['id'] = 1;header("Location: welcome.php");}}\[/code\]
 
Back
Top