Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- //log out if ?logout=true
- if($_GET["logout"]){
- $_SESSION["loggedIn"]=false;
- header('Location: '. $_SERVER['SCRIPT_NAME']);
- }
- //sha-256 hash of password
- $password = '8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4';
- if(empty($_SESSION["loggedIn"])){
- if(isset($_POST["password"])){
- if(hash('sha256', $_POST['password'])==$password){
- $_SESSION["loggedIn"]=true;
- } else{
- echo "Incorrect password! <br>";
- }
- }
- }
- if($_SESSION["loggedIn"] == true){
- print '
- You are logged in!<br>
- <a href="?logout=true">Logout</a>
- <!-- Main HTML page goes here-->
- ';
- } else{
- print ' <h3>Login</h3>
- <form action="#" method="post">
- Password: <input type="password" name="password"><br>
- <input type="submit" value="Login!" />
- </form>
- ';
- }
- ?>
- <?php
- session_start();
- if($_SESSION["loggedIn"]=false){
- header('Location: login.php');
- } else {
- //stuff goes here
- }
Add Comment
Please, Sign In to add comment