Jump to content

Recommended Posts


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

[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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.