Advertisement
WarpCut

Index

Jun 6th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <?php
  3.     // Start the session
  4.     session_start();
  5.  
  6.    
  7.     // Connessione al DB
  8.     $dbconn = pg_pconnect("host=localhost port=5432 dbname=postgres user=postgres password=Fleabasser96")
  9.     or die('Could not connect: ' . pg_last_error());
  10.    
  11.     // User e psw = post
  12.     $username = $_POST['username'];
  13.     $password = $_POST['password'];
  14.  
  15.     // Log-in query e variabile di controllo
  16.     $sql_log = "SELECT email,password FROM public.utenti WHERE email='$username' AND password='$password'";
  17.     $success = false;
  18.    
  19.     // Messaggio stampato sotto a button
  20.     $error = "";
  21.  
  22.     // Se già loggato rimanda a account
  23.     if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {
  24.         $error = "success";
  25.         header('Location: account.php');
  26.     }
  27.        
  28.     // Se sono state inserite le credenziali
  29.         //controllo se esiste un elemento trasformando success a true
  30.         //se è true loggo
  31.         //se è false modifico la stringa da stampare
  32.    
  33.     if (isset($_POST['username']) && isset($_POST['password'])) {
  34.         $result = pg_query($dbconn, $sql_log);
  35.         while($row = pg_fetch_row($result)) {
  36.             $success = true;
  37.         }
  38.         if($success == true) {
  39.             $_SESSION['loggedIn'] = true;
  40.             header('Location: account.php');
  41.             $error = "Valid credentials!";
  42.         } else {
  43.             $_SESSION['loggedIn'] = false;
  44.             $error = "Invalid username or password!";
  45.         }    
  46.         pg_free_result($result);
  47.  
  48.         pg_close($dbconn);
  49.         /*
  50.         if ($_POST['username'] == $username && $_POST['password'] == $password) {
  51.             $_SESSION['loggedIn'] = true;
  52.             header('Location: account.php');
  53.         } else {
  54.             $_SESSION['loggedIn'] = false;
  55.             $error = "Invalid username and password!";
  56.         }*/
  57.     }
  58.    
  59. ?>
  60.  
  61. <html>
  62.     <head>
  63.         <title>DoungeonAsDB : Official</title>
  64.         <?php include ('lib/header.php'); ?>
  65.     </head>
  66.     <body>
  67.         <div class="background-wrap">
  68.             <video id="bgvideo" preload="auto" autoplay="true" loop="loop" muted="muted" poster="">
  69.                 <source src="video.mov" type="video/mp4">
  70.             </video>
  71.         </div>
  72.         <div class="content">
  73.             <h1>Dungeon As DB</h1>
  74.             <div id="log">
  75.                 <form method="post" action="index.php">
  76.                     <label for="username">Email</label><br>
  77.                     <input class="inputborder" type="text" name="username" id="username" placeholder="Enter Email" required>
  78.                     <br><br>
  79.                     <label for="password">Password</label><br>
  80.                     <input class="inputborder" type="password" name="password" id="password" placeholder="Enter Password" required>
  81.                     <br>
  82.                     <button type="submit">Login</button>
  83.                     <br>
  84.                     <?php
  85.                     echo "<p style='color:white;'>".$error."</p>";
  86.                     ?>
  87.                     <div class ="register">
  88.                         <span class="psw">New to DoungeonASDB? <a href="register.php"> Sign Up Now. </a></span>
  89.                     </div>
  90.                 </form>
  91.             </div>
  92.         </div>
  93.     </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement