Posted By

ryarwood on 07/20/10


Tagged

login php


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

leongaban
esritter
joacoleo
osirisinternet
thomas-h


Check Login PHP


 / Published in: PHP
 

  1. $host=$p11server; // Host name
  2. $username=$p11username; // Mysql username
  3. $password=$p11password; // Mysql password
  4. $db_name=$p11database; // Database name
  5. $tbl_name="users"; // Table name
  6.  
  7. // Connect to server and select databse.
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. // To protect MySQL injection (more detail about MySQL injection)
  16. $myusername = stripslashes($myusername);
  17. $mypassword = stripslashes($mypassword);
  18. $myusername = mysql_real_escape_string($myusername);
  19. $mypassword = mysql_real_escape_string($mypassword);
  20.  
  21. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  22. $result=mysql_query($sql);
  23.  
  24. // Mysql_num_row is counting table row
  25. $count=mysql_num_rows($result);
  26. // If result matched $myusername and $mypassword, table row must be 1 row
  27.  
  28. if($count==1){
  29. // Register $myusername, $mypassword and redirect to correct location
  30. session_register("myusername");
  31. session_register("mypassword");
  32. header("location:main.php");
  33. }
  34. else {
  35. header("location:index.php?messalert=pw");
  36. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: uobradbury on July 29, 2010

I was reading through this and when I got to line 29 and read the comment I wondered why it said that it was pointing towards login_success.php when the two headers point to main.php & index.php?messalert=pw.

Posted By: uobradbury on July 29, 2010

I was reading through this and when I got to line 29 and read the comment I wondered why it said that it was pointing towards login_success.php when the two headers point to main.php & index.php?messalert=pw.

Posted By: ryarwood on July 31, 2010

This was hacked up from something else back in the day and I took my own spin on it. I took that out. Good eye.

You need to login to post a comment.