Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2. session_name('MYSESSION');
  3. session_set_cookie_params(0, '/~cgreenheld/');
  4. session_start();
  5. ?>
  6.  
  7. <?php
  8. if($_SESSION['authorisation'] == 'knownuser') {
  9.  
  10. echo '<ul class="log">';
  11. echo '<li><h4>You are logged in "'.$_SESSION['user'].'"</h4></li>';
  12. echo '<li><a href="logout.php">Logout</a></li>';
  13. echo "</ul>";
  14. }
  15. else {
  16. echo "<h4>You are not logged in</h4>";
  17. }
  18. ?>
  19. <?php
  20.  
  21.  
  22. if($_SESSION['authorisation'] == 'knownuser') {
  23. echo "<ul>";
  24. echo "<li><h4>You are logged in and already have an account</h4></li>";
  25. echo '<li><a href="index.php">Return Home</a></li>';
  26. echo "</ul>";
  27. }
  28. else {
  29.  
  30. echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
  31. echo '<fieldset class="login">';
  32. echo "<h2>Login</h2>";
  33. echo "<ul>";
  34. echo '<li><label for="Username"> Username: </label> <input type="text" name="Username" id="Username"></li>';
  35. echo '<li><label for="Password"> Password: </label> <input type="password" name="Password" id="Password"></li>';
  36. echo '<li><input type="submit" value="Login"><li>';
  37. echo "</ul>";
  38. echo "</fieldset>";
  39. echo "</form>";
  40. }
  41. if ((isset($_POST['Password'])) && $_POST['Password'] != "") {
  42.  
  43. $conn= new mysqli("localhost", "my_user", "my_password", "world"); //changed for the sake of this question
  44.  
  45. $match_Username = '%';
  46. $match_Password ='';
  47.  
  48. if(isset($_POST['Password'])) {
  49. $clean_Password = mysqli_real_escape_string($conn, $_POST['Password']);
  50. $match_Password = sha1($clean_Password);
  51. }
  52.  
  53. if (isset($_POST['Username'])) {
  54. $clean_Username = mysqli_real_escape_string($conn, $_POST['Username']);
  55. $match_Username = $clean_Username;
  56. }
  57.  
  58. echo $query = "select * from User WHERE Username = '$match_Username' and Password = '$match_Password';";
  59. $result = $conn->query($query);
  60.  
  61. if ($result->num_rows==1) {
  62. $_SESSION['authorisation'] = 'knownuser';
  63. $_SESSION['user'] = $_POST['Username'];
  64. header("Location: index.php");
  65. exit;
  66. } else {
  67. $_SESSION['authorisation'] = 'unknownuser';
  68. header("Location: error.php");
  69. exit;
  70. }
  71.  
  72. }
  73.  
  74. if($_SESSION['authorisation'] == 'knownuser') {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement