Guest User

Untitled

a guest
Aug 1st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $host = "localhost"; //localhost name
  6. $username = "root"; //sql username
  7. $password = "root"; //sql password
  8. $db_name = "test"; //database name
  9. $tbl_name = "members"; //table name
  10.  
  11. // username and password sent from FORM
  12. $myusername = $_POST['myusername'];
  13. $mypassword = $_POST['mypassword'];
  14.  
  15.  
  16. // conect to server and select database if username and password are true
  17. if ($myusername && $mypassword){
  18.  
  19. $connect = mysql_connect("$host", "$username", "$password") or die("could not connect");
  20. mysql_select_db($db_name) or die ("could not connect to database");
  21.  
  22.  
  23. $query = mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'");
  24.  
  25.  
  26. // mysql_num_row is counting table row
  27. $count = mysql_num_rows($query);
  28. // if result is a match $username and $password, tbl row must be 1 row
  29.  
  30. //echo $count;
  31.  
  32.  
  33. if ($count == 1){
  34.  
  35. // register $username $password and redirect to file "checklogin.php"
  36. session_register("myusername");
  37. $_SESSION['username'] = $myusername; //creating a session with the username
  38. session_register("mypassword");
  39. header("location:login_success.php");
  40. }
  41.  
  42. else {
  43. echo "you have wrong username or password try again";
  44. }
  45.  
  46. }
  47.  
  48. else {
  49. die("please enter username and password!!!!!!");
  50. }
  51.  
  52.  
  53.  
  54. // security against mysql injections
  55. /*
  56. $myusername = stripcslashes($myusername);
  57. $mypassword = stripcslashes($mypassword);
  58. $myusername = mysql_real_escape_string($username);
  59. $mypassword = mysql_real_escape_string($mypassword);
  60. */
  61.  
  62.  
  63.  
  64.  
  65.  
  66. ?>
Add Comment
Please, Sign In to add comment