Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // bluexaren :)
- ?>
- <html>
- <head>
- <title>welcome to pwnthecode</title>
- <style type='text/css'>
- body {
- background: grey;
- color:white;
- }
- #login_but {
- background: white;
- border:1px solid black;
- margin:3px 2px 3px;
- padding:3px 2px 3px;
- width:210px;
- height:30px;
- }
- </style>
- </head>
- <body>
- <div align="center">
- <br/><br/><br/><br/><br/>
- <h3>Welcome</h3>
- <?php
- // functions
- function authentificate() {
- $username = "Andrei";
- $password = "bluexaren";
- echo <<<loginform
- <h2>Login</h2>
- <form action='{$_SERVER['PHP_SELF']}' method='POST'>
- <label for='username'>Username : </label><input type='text' name='username' value=''/><br/>
- <label for='password'>Password : </label><input type='password' name='password' value=''/><br/>
- <input type='submit' name='login' value='Login' id='login_but'/>
- </form>
- loginform;
- if(isset($_POST['login'])) {
- if(empty($_POST['username']) OR empty($_POST['password'])) {
- echo "Username and Password are required !";
- } elseif(strtolower($_POST['username']) == strtolower($username) AND strtolower($_POST['password']) == strtolower($password)) {
- setcookie('logged_in', TRUE, time()+1337);
- setcookie('username', $_POST['username'], time()+1337);
- $_SESSION['cookie'] = $_COOKIE['logged_in'];
- $_SESSION['username'] = $_COOKIE['username'];
- header("Location: {$_SERVER['PHP_SELF']}");
- } else {
- echo "Incorrect username or password !";
- }
- }
- }
- //#######################################################################################################
- // getting the action variable
- if(!isset($_GET['action'])) {
- $action = NULL;
- } else {
- $action = $_GET['action'];
- }
- // ############################
- switch($action) {
- default :
- if(!$_SESSION['cookie'] || $_SESSION['cookie'] = NULL || $_SESSION['cookie'] = FALSE) {
- authentificate();
- } elseif($_SESSION['cookie'] = TRUE) {
- echo 'Logged in as <b>'.$_SESSION['username'].'</b><br/>';
- echo 'Welcome back <b>'.$_SESSION['username'].'</b><br/>';
- echo 'You wanna <a href="?logout">Logout</a> ?';
- if(isset($_GET['logout'])) {
- if($_SESSION['cookie'] = TRUE ) {
- $_SESSION['cookie'] = FALSE;
- header("Location: {$_SERVER['PHP_SELF']}");
- }
- else {
- echo "You are not logged in !";
- }
- }
- }
- break;
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement