Guest User

Untitled

a guest
Mar 1st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. login_page.php
  2.  
  3. <form action="verify.php" method="post">
  4. User Name:<br>
  5. <input type="text" name="username"><br><br>
  6. Password:<br>
  7. <input type="password" name="password"><br><br>
  8. <input type="submit" name="submit" value="Login">
  9. </form>
  10. verify.php
  11.  
  12. <?php
  13. if(isset($_POST['submit'])){
  14. $dbHost = "localhost"; //Location Of Database usually its localhost
  15. $dbUser = "xxxx"; //Database User Name
  16. $dbPass = "xxxxxx"; //Database Password
  17. $dbDatabase = "db_name"; //Database Name
  18.  
  19. $db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database.");
  20. //Connect to the databasse
  21. mysql_select_db($dbDatabase, $db)or die("Couldn't select the database.");
  22. //Selects the database
  23.  
  24. /*
  25. The Above code can be in a different file, then you can place include'filename.php'; instead.
  26. */
  27.  
  28. //Lets search the databse for the user name and password
  29. //Choose some sort of password encryption, I choose sha256
  30. //Password function (Not In all versions of MySQL).
  31. $usr = mysql_real_escape_string($_POST['username']);
  32. $pas = hash('sha256', mysql_real_escape_string($_POST['password']));
  33. $sql = mysql_query("SELECT * FROM users_table
  34. WHERE username='$usr' AND
  35. password='$pas'
  36. LIMIT 1");
  37. if(mysql_num_rows($sql) == 1){
  38. $row = mysql_fetch_array($sql);
  39. session_start();
  40. $_SESSION['username'] = $row['username'];
  41. $_SESSION['fname'] = $row['first_name'];
  42. $_SESSION['lname'] = $row['last_name'];
  43. $_SESSION['logged'] = TRUE;
  44. header("Location: users_page.php"); // Modify to go to the page you would like
  45. exit;
  46. }else{
  47. header("Location: login_page.php");
  48. exit;
  49. }
  50. }else{ //If the form button wasn't submitted go to the index page, or login page
  51. header("Location: index.php");
  52. exit;
  53. }
  54. ?>
  55. users_page.php
  56.  
  57. <?php
  58. session_start();
  59. if(!$_SESSION['logged']){
  60. header("Location: login_page.php");
  61. exit;
  62. }
  63. echo 'Welcome, '.$_SESSION['username'];
  64. ?>
Add Comment
Please, Sign In to add comment