Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php
  2. if( $_SESSION['auth'] != 1 ) {
  3. require( 'login.php' );
  4. }
  5. else {
  6. echo "hello";
  7. }
  8. ?>
  9.  
  10. <?php
  11. $name = $_POST['name'];
  12. $pass = $_POST['pass'];
  13.  
  14. if( isset($name) || isset($pass) )
  15. {
  16. if( empty($name) ) {
  17. die ("ERROR: Please enter username!");
  18. }
  19. if( empty($pass) ) {
  20. die ("ERROR: Please enter password!");
  21. }
  22.  
  23.  
  24. if( $name == "<some name>" && $pass == "<some password>" )
  25. {
  26. // Authentication successful - Set session
  27. session_start();
  28. $_SESSION['auth'] = 1;
  29. setcookie("username", $_POST['name'], time()+(84600*30));
  30. echo "Access granted!";
  31. }
  32. else {
  33. echo "ERROR: Incorrect username or password!";
  34. }
  35. }
  36.  
  37.  
  38. // If no submission, display login form
  39. else {
  40. ?>
  41. <html>
  42. <head></head>
  43. <body>
  44. <center>
  45. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  46. Username: <input type="text" name="name" value="<?php echo $_COOKIE['username']; ?>">
  47. <p />
  48. Password: <input type="password" name="pass">
  49. <p />
  50. <input type="submit" name="submit" value="Log In">
  51. </center>
  52. </body>
  53. </html>
  54. <?php
  55. }
  56. ?>
  57.  
  58. header('Location: index.php');
  59. exit;
  60.  
  61. session_start();
  62. if (!isset($_SESSION['auth']) || $_SESSION['auth'] != 1) {
  63. header('Location: login.php');
  64. exit();
  65. }
  66. echo 'Hello';
  67.  
  68. session_start();
  69. if( $name == "<some name>" && $pass == "<some password>" )
  70. {
  71. // Authentication successful - Set session
  72. $_SESSION['auth'] = 1;
  73. setcookie("username", $_POST['name'], time()+(84600*30));
  74. header('Location: index.php');
  75. exit();
  76. }
  77. else {
  78. echo "ERROR: Incorrect username or password!";
  79. }
  80.  
  81. $name = isset($_POST['name']) ? $_POST['name'] : '';
  82.  
  83. $_SESSION['user'] = 'John';
  84.  
  85. header('Location: index.php');
  86. exit;
  87.  
  88. <?php
  89. session_start();
  90. if (empty($_SESSION['user'])) {
  91.  
  92. $name = isset($_POST['name']) ? $_POST['name'] : '';
  93. $pass = isset($_POST['pass']) ? $_POST['pass'] : '';
  94.  
  95. if ($name != '' || $pass != '')
  96. {
  97. if ($name === '')
  98. die("ERROR: Please enter the username!");
  99.  
  100. if ($pass === '')
  101. die("ERROR: Please enter the password!");
  102.  
  103. if ($name == "test" && $pass == "test") {
  104.  
  105. // authentication successful, save username in session:
  106. $_SESSION['user'] = 'John';
  107.  
  108. // redirect to index.php to welcome the logged in user:
  109. header('Location: index.php');
  110. exit;
  111. }
  112. else {
  113. die("ERROR: Incorrect username or password!");
  114. }
  115. }
  116.  
  117. // no submitted data, display form:
  118. ?>
  119. <html>
  120. <head></head>
  121. <body>
  122. <center>
  123. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  124. Username: <input type="text" name="name" value=""><br>
  125. Password: <input type="password" name="pass"><br>
  126. <input type="submit" value="Log In">
  127. </form>
  128. </center>
  129. </body>
  130. </html>
  131. <?php
  132. }
  133. else {
  134. // info about current user is stored in session, welcome this user:
  135. echo "hello " . $_SESSION['user'];
  136. }
  137. ?>
  138.  
  139. if( $name == "<some name>" && $pass == "<some password>" )
  140. {
  141. // Authentication successful - Set session
  142. session_start();
  143. $_SESSION['auth'] = 1;
  144. setcookie("username", $_POST['name'], time()+(84600*30));
  145. //echo "Access granted!";
  146. header("Location: index.php");
  147. die('');
  148. }
  149.  
  150. $_SESSION['user']=$_POST['name'];
  151.  
  152. if (isset($_SESSION['user']))
  153. echo "Hello, " . $_SESSION['user'];
  154.  
  155. if($_SESSION['auth'] != 1) {
  156. require('login.php');
  157. }
  158. // Either way always print.
  159. echo "hello";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement