romio Posted September 18, 2006 Share Posted September 18, 2006 This is my code which I use for my Login page, I would appreciate if anyone could tell me if its good enough, if not, then how can I improve it.[code]if ((isset($_POST['username'])) && (isset($_POST['username']))) { $loginUsername = mysql_escape_string($_POST['username']); $password = mysql_escape_string(md5($_POST['password'])); $checkaccess = "SELECT username,password FROM login WHERE username = '$loginUsername' AND password = '$password'"; $Login = mysql_query($checkaccess) or die(mysql_error()); $loginFoundUser = mysql_num_rows($Login); if ($loginFoundUser){ setcookie('Logged', 'True', time()+60*60); header('Location: index.php'); exit; }else{ $errorMessage = true; }}[/code] Link to comment https://forums.phpfreaks.com/topic/21129-login-page-code-advice/ Share on other sites More sharing options...
Zane Posted September 18, 2006 Share Posted September 18, 2006 [code] $loginFoundUser = mysql_num_rows($Login); if ($loginFoundUser){ setcookie('Logged', 'True', time()+60*60); header('Location: index.php'); exit; }else{ $errorMessage = true; }[/code][quote=php.net/mysql_num_rows]mysql_num_rows return the number of rows in a result set on success, or FALSE on failure.[/quote]$loginFoundUser will only be false if the SQL statement has an error in it..you'll have change you if statement to[code]if ($loginFoundUser == 1{[/code] Link to comment https://forums.phpfreaks.com/topic/21129-login-page-code-advice/#findComment-93839 Share on other sites More sharing options...
romio Posted September 18, 2006 Author Share Posted September 18, 2006 Thx zanus. Link to comment https://forums.phpfreaks.com/topic/21129-login-page-code-advice/#findComment-93848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.