Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP FOR SQL RELATED LOGINS.
- <?php
- session_start();
- $username = $_POST["username"];
- $password=$_POST["password"];
- if ($username=="John" && $password=="pass"){
- $_SESSION['login']= $username;
- header("location: index.php");
- }
- else{
- header("location: login.html");
- }
- ?>
- PHP HEADER FOR ANY PAGE THAT REQUIRES A LOGGED IN USER
- <?php
- session_start();
- if (!isset($_SESSION['login'])) {
- header("location: login.html");
- }
- else{
- print "You've successfully logged in.<br>";
- session_destroy( ); // simulation of logout
- }
- ?>
- USER LOGIN FORM VALIDATION
- <?php
- session_start();
- if(!empty($_POST["username"])) // if username not empty
- {
- $username = $_POST["username"];
- $password = $_POST["password"];
- if($username == "user1") { // Simulation of
- database login query for $username
- if($password == "pass1") { // Simulation
- of database login query for $password
- $_SESSION['login'] = $username;
- echo 4; // Success!
- }
- else echo 3; // username OK but password
- incorrect
- }
- else echo 2; //username incorrect
- }
- else echo 1; // usernameis blank
- ?>
- FOR THE LOGOUT.PHP
- <?php
- session_start();
- session_destroy();
- echo "You have logged out! If your browser does not redirect you, click the link below!<br><br>";
- // sleep for 4 seconds
- sleep(4)
- header( 'Location: /index.html' );
- // Shannon, honestly dunno if that redirect to index works,
- // but, whatever its worth a shot for some marks.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement