Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 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 = mysql_real_escape_string(stripslashes($uname));
  41.     $passwd = mysql_real_escape_string(stripslashes($passwd));
  42.  
  43.     $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$passwd'";
  44.     $result=mysql_query($sql);
  45.  
  46.  
  47.     $count=mysql_num_rows($result);
  48.  
  49.  
  50.     if($count==1){
  51.  
  52.  
  53.         $_SESSION['uname'] = $uname;
  54.         $_SESSION['passwd'] = $passwd;
  55.  
  56.         Header("Location: userarea.php");
  57.     } else {
  58.         echo "<html>
  59.         <body>
  60.         <br />
  61.         <h3 align=center>Wrong username or password.</h3>
  62.         <br />
  63.         <p align=center>
  64.         <a href=index.php>Go back and try again.</a></p>
  65.         <p align=center>If you are not redirected automatically within a few
  66.         seconds then please click on the link above.</p>
  67.         <script type=text/javascript><!--
  68.         setTimeout('Redirect()',3000);
  69.         function Redirect()
  70.         {
  71.           location.href = 'index.php';
  72.         }
  73.         // --></script>
  74.         </body>
  75.         </html>";
  76.     }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement