Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if( !isset($_SESSION['myusername']) )
  4. header("location:checklogin.php");
  5. ?>
  6.  
  7. <?php
  8.  
  9. $host="localhost"; // Host name
  10. $username="garbo45"; // Mysql username
  11. $password="water5"; // Mysql password
  12. $db_name="garbo45"; // Database name
  13. $tbl_name="members"; // Table name
  14.  
  15. // Connect to server and select database.
  16. $conn = new mysqli($host, $username, $password, $db_name);
  17. if ($conn->connect_error) die($conn->connect_error);
  18.  
  19. // username and password sent from form
  20. $myusername=$_POST['myusername'];
  21. $mypassword=$_POST['mypassword'];
  22.  
  23. $myusername = stripslashes($myusername);
  24. $mypassword = stripslashes($mypassword);
  25. $myusername = mysqli_real_escape_string($conn, $myusername);
  26. $mypassword = mysqli_real_escape_string($conn, $mypassword);
  27. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  28. $result=mysqli_query($conn, $sql);
  29.  
  30. // Mysql_num_row is counting table row
  31. $count=mysqli_num_rows($result);
  32.  
  33. // If result matched $myusername and $mypassword, table row must be 1 row
  34. if($count==1){
  35.  
  36. // Register $myusername, $mypassword and redirect to file "loginsuccess.php"
  37. $_SESSION['myusername']= "myusername";
  38. $_SESSION['mypassword']= "mypassword";
  39. header("location:index.php");
  40. }
  41. else {
  42. echo "Wrong Username or Password";
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement