Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. $host=""; // Host name
  3. $username=""; // Mysql username
  4. $password=""; // Mysql password
  5. $db_name=""; // Database name
  6. $tbl_name=""; // Table name
  7.  
  8. // Connect to server and select databse.
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect to DB");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12. // username and password sent from form
  13. $uname=$_POST['uname'];
  14. $passwd=$_POST['passwd'];
  15.  
  16. //Checking for empty fields
  17. if (empty($uname) || empty($passwd)) {
  18.     echo "<html>
  19. <body>
  20. <br />
  21. <h3 align=center>Please fill out all fields.</h3>
  22. <br />
  23. <p align=center>
  24. <a href=index.php>Go back and try again.</a></p>
  25. <p align=center>If you are not redirected automatically within a few
  26. seconds then please click on the link above.</p>
  27. <script type=text/javascript><!--
  28. setTimeout('Redirect()',3000);
  29. function Redirect()
  30. {
  31.  location.href = 'index.php';
  32. }
  33. // --></script>
  34. </body>
  35. </html>";
  36.     die;
  37. }
  38.  
  39.  
  40. $uname = stripslashes($uname);
  41. $passwd = stripslashes($passwd);
  42. $uname = mysql_real_escape_string($uname);
  43. $passwd = mysql_real_escape_string($passwd);
  44.  
  45. $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$passwd'";
  46. $result=mysql_query($sql);
  47.  
  48.  
  49. $count=mysql_num_rows($result);
  50.  
  51.  
  52. if($count==1){
  53.  
  54.  
  55. session_register("uname");
  56. session_register("passwd");
  57. header("location:userarea.php");
  58. }
  59. else {
  60. echo "<html>
  61. <body>
  62. <br />
  63. <h3 align=center>Wrong username or password.</h3>
  64. <br />
  65. <p align=center>
  66. <a href=index.php>Go back and try again.</a></p>
  67. <p align=center>If you are not redirected automatically within a few
  68. seconds then please click on the link above.</p>
  69. <script type=text/javascript><!--
  70. setTimeout('Redirect()',3000);
  71. function Redirect()
  72. {
  73.  location.href = 'index.php';
  74. }
  75. // --></script>
  76. </body>
  77. </html>";
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement