Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. login.php
  2.  
  3.  
  4.     // Start the session
  5.     session_start();
  6.  
  7.     // Defines username and password.
  8.  
  9.     $username = "admin";
  10.     $password = "password";
  11.  
  12.     // Error message
  13.     $error = "";
  14.  
  15.     // jestli jsi lognuty
  16.     if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {
  17.         $error = "success";
  18.         header('Location: success.php');
  19.     }
  20.        
  21.  //  jestli je vse zadane
  22.     if (isset($_POST['username']) && isset($_POST['password'])) {
  23.         if ($_POST['username'] == $username && $_POST['password'] == $password) {
  24.             $_SESSION['loggedIn'] = true;
  25.             header('Location: success.php');
  26.         } else {
  27.             $_SESSION['loggedIn'] = false;
  28.             $error = "Ĺ patnĂ© jmĂ©no nebo heslo :D";
  29.         }
  30.     }
  31.    
  32.  
  33.    
  34.    
  35.    
  36. ?>
  37.  
  38. <html>
  39.     <head>
  40.         <title>Login</title>
  41. <link rel="stylesheet" type="text/css" href="style.css">
  42.     </head>
  43.    
  44.     <body style="text-align: center;">
  45.    
  46.    
  47.    
  48.    
  49.         <!-- Output error message if any -->
  50.         <?php echo $error; ?>
  51.        
  52.    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>>    
  53.        
  54.         <!-- form for login -->
  55.        
  56.       <div id="frm">
  57.         <form method="post" action="login.php" style="background-color: lime">
  58.             <label for="username">Jmeno:</label><br/>
  59.             <input type="text" name="username" id="username"><br/>
  60.             <label for="password">Heslo:</label><br/>
  61.             <input type="password" name="password" id="password"><br/>
  62.             <input type="submit" value="Prihlasit!!" id="btn" name="btn">
  63.         </form>
  64.        
  65.  <form action="/index.php" style="background-color: lime">
  66.  <br>
  67. <input type="submit" value="ZPET" style="text-align:left" id="btn2" name="btn2">
  68.  </form>
  69. </div>
  70.  
  71. <br><br><br><br><br><br><br><br><br><br>
  72.     </body>
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. success.php
  80.  
  81. <?php
  82.   // Start the session
  83.     ob_start();
  84.     session_start();
  85.  
  86.     // Check to see if actually logged in. If not, redirect to login page
  87.     if (!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] == false) {
  88.         header("Location: login.php");   }
  89.         ?>
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. logout.php
  98.  
  99. <?php
  100.     session_start();
  101.     $_SESSION['loggedIn'] = false;
  102.     header("Location: login.php");
  103. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement