Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. Checklogin:
  2. ------------------------------------
  3.  
  4.  
  5. <?php
  6. $host="localhost"; // Host name
  7. $username="root"; // Mysql username
  8. $password=""; // Mysql password
  9. $db_name=""; // Database name
  10. $tbl_name="login"; // Table name
  11.  
  12. // Connect to server and select databse.
  13. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  14. mysql_select_db("$db_name")or die("cannot select DB");
  15.  
  16. // username and password sent from form
  17. $myusername=$_POST['myusername'];
  18. $mypassword=$_POST['mypassword'];
  19. $user = $_POST['myusername'];
  20.  
  21. // To protect MySQL injection (more detail about MySQL injection)
  22. $myusername = stripslashes($myusername);
  23. $mypassword = stripslashes($mypassword);
  24. $myusername = mysql_real_escape_string($myusername);
  25. $mypassword = mysql_real_escape_string($mypassword);
  26.  
  27. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  28. $result=mysql_query($sql);
  29.  
  30. // Mysql_num_row is counting table row
  31. $count=mysql_num_rows($result);
  32. // If result matched $myusername and $mypassword, table row must be 1 row
  33.  
  34. if($count==1){
  35. // Register $myusername, $mypassword and redirect to file "login_success.php"
  36.  
  37. $sql1= "select res_id from login where username='$user' and password ='$mypassword'";
  38. $result1=mysql_query($sql1);
  39. $lol = mysql_fetch_row($result1);
  40.  
  41.  
  42. $_SESSION['mypassword'] = $mypassword;
  43. $_SESSION['myusername'] = $myusername;
  44.  
  45. header("location:login_success.php");
  46. }
  47. else {
  48. header("location:error.php");
  49. }
  50. ?>
  51.  
  52. ---------------------------------
  53. Login_success.php
  54.  
  55. <?
  56. session_start();
  57. if(!session_is_registered(myusername)){
  58. header("location:main_login.php");
  59. }
  60.  
  61.  
  62. $host="localhost"; // Host name
  63. $username="root"; // Mysql username
  64. $password=""; // Mysql password
  65. $db_name=""; // Database name
  66. $tbl_name="login"; // Table name
  67.  
  68. // Connect to server and select databse.
  69. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  70. mysql_select_db("$db_name")or die("cannot select DB");
  71.  
  72.  
  73.  
  74.  
  75. ?>
  76.  
  77.  
  78. <html>
  79. <body>
  80.  
  81. <?
  82. echo $_SESSION['myusername'];
  83. ?>
  84.  
  85.  
  86.  
  87.  
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement