Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. //Connection and select database go in here
  6.  
  7. // username and password sent from form
  8. $myusername=$_POST['Email'];
  9. $mypassword=$_POST['User_Password'];
  10.  
  11. // To protect MySQL injection
  12. $myusername = stripslashes($myusername);
  13. $mypassword = stripslashes($mypassword);
  14. $myusername = mysql_real_escape_string($myusername);
  15. $mypassword = mysql_real_escape_string($mypassword);
  16.  
  17. $sql="SELECT User_ID, Email, User_Password FROM $tbl_name WHERE Email='$myusername' and User_Password='$mypassword'";
  18. $result=mysql_query($sql);
  19.  
  20. // Mysql_num_row counts table row
  21. $count=mysql_num_rows($result);
  22.  
  23. // If result matched $myusername and $mypassword, table row must be 1 row
  24. if($count==1){
  25.  
  26. // is_auth to make sure they can view other pages that need credentials.
  27. $_SESSION['is_auth'] = true;
  28. $_SESSION['User_ID'] = $result->User_ID;
  29.  
  30. // Once the sessions variables have been set, redirect them to the landing page / home page.
  31. header('location: ../View/main.php');
  32. exit;
  33. }
  34.  
  35. else {
  36. $error = "Please enter an email and password to login.";
  37. }
  38. header("location:../View/mainUnauthenticated.php");
  39.  
  40. <?php
  41.  
  42. session_start();
  43. echo $_SESSION['User_ID'];
  44.  
  45. // Test the session to see if is_auth flag was set (meaning they logged in successfully)
  46.  
  47. // If test fails, send the user to homepage and prevent rest of page being shown.
  48.  
  49. if (!isset($_SESSION["is_auth"])) {
  50. header("location: ../View/mainUnauthenticated.php");
  51. exit;
  52. }
  53. else if (isset($_REQUEST['logout']) && $_REQUEST['logout'] == "true") {
  54. // At any time we can logout by sending a "logout" value which will unset the "is_auth" flag.
  55. // We can also destroy the session if so desired.
  56. unset($_SESSION['is_auth']);
  57. session_destroy();
  58. // After logout, send them back to homepage
  59. header("location: ../View/mainUnauthenticated.php");
  60. exit;
  61. }
  62. ?>
  63.  
  64. <?php include('../Controller/is_auth.php')
  65.  
  66. ?>
  67.  
  68.  
  69. <p>
  70. <input type="text" name="User_ID" id="User_ID" value="<?php echo $_SESSION['User_ID'];?>"/>
  71. </p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement