Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. // bluexaren :)
  5.  
  6. ?>
  7. <html>
  8.     <head>
  9.         <title>welcome to pwnthecode</title>
  10.         <style type='text/css'>
  11.            
  12.     body {
  13.     background: grey;
  14.     color:white;
  15.     }
  16.     #login_but {
  17.       background: white;
  18.       border:1px solid black;
  19.       margin:3px 2px 3px;
  20.       padding:3px 2px 3px;
  21.       width:210px;
  22.       height:30px;
  23.      }
  24.  
  25.             </style>
  26.     </head>
  27.     <body>
  28.         <div align="center">
  29.             <br/><br/><br/><br/><br/>
  30.             <h3>Welcome</h3>
  31.  
  32.            
  33. <?php
  34. // functions
  35. function authentificate() {
  36. $username = "Andrei";
  37. $password = "bluexaren";  
  38. echo <<<loginform
  39. <h2>Login</h2>
  40. <form action='{$_SERVER['PHP_SELF']}' method='POST'>
  41. <label for='username'>Username : </label><input type='text' name='username' value=''/><br/>
  42. <label for='password'>Password : </label><input type='password' name='password' value=''/><br/>
  43. <input type='submit' name='login' value='Login' id='login_but'/>
  44. </form>
  45. loginform;
  46. if(isset($_POST['login'])) {
  47.     if(empty($_POST['username']) OR empty($_POST['password'])) {
  48.         echo "Username and Password are required !";
  49.     } elseif(strtolower($_POST['username']) == strtolower($username) AND strtolower($_POST['password']) == strtolower($password)) {
  50.         setcookie('logged_in', TRUE, time()+1337);
  51.         setcookie('username', $_POST['username'], time()+1337);
  52.         $_SESSION['cookie'] = $_COOKIE['logged_in'];
  53.         $_SESSION['username'] = $_COOKIE['username'];
  54.         header("Location: {$_SERVER['PHP_SELF']}");
  55.     } else {
  56.         echo "Incorrect username or password !";
  57.     }
  58.    
  59.    
  60. }
  61. }
  62. //#######################################################################################################
  63.  
  64. // getting the action variable
  65. if(!isset($_GET['action'])) {
  66.     $action = NULL;
  67. } else {
  68. $action = $_GET['action'];
  69. }
  70. // ############################
  71.  
  72.  
  73. switch($action) {
  74.     default :
  75.     if(!$_SESSION['cookie'] || $_SESSION['cookie'] = NULL || $_SESSION['cookie'] = FALSE) {
  76.     authentificate();
  77. } elseif($_SESSION['cookie'] = TRUE) {
  78.     echo 'Logged in as <b>'.$_SESSION['username'].'</b><br/>';
  79.     echo 'Welcome back <b>'.$_SESSION['username'].'</b><br/>';
  80.     echo 'You wanna <a href="?logout">Logout</a> ?';
  81.     if(isset($_GET['logout'])) {
  82.         if($_SESSION['cookie'] = TRUE ) {
  83.         $_SESSION['cookie'] = FALSE;
  84.         header("Location: {$_SERVER['PHP_SELF']}");
  85.         }
  86.         else {
  87.             echo "You are not logged in !";
  88.         }
  89.     }
  90. }
  91. break;
  92.        
  93. }
  94.  
  95.  
  96. ?>
  97.         </div>
  98.     </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement