Advertisement
Guest User

LOGIN.PHP

a guest
May 30th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="UTF-8">
  5.     <title>Area Riservata | Autenticati</title>
  6.    
  7.         <link rel="stylesheet" href="css/style2.css">
  8.    
  9.   </head>
  10.  
  11.   <body>
  12.  
  13. <?php
  14. session_start();
  15.  
  16. function Open($dbname) {
  17.  
  18.    $con = new mysqli("127.0.0.1","root","",$dbname);
  19.  
  20.    if ($con->connect_errno) {
  21.      echo "<h2>".$con->connect_error."</h2>";
  22.      exit();
  23.    }
  24.    else    
  25.          
  26.    return $con;
  27.  }
  28.  
  29.  function Query($con,$sql) {
  30.     $res = $con->query($sql);
  31.        if (!$res)      
  32.       echo "<h2>".$con->error."</h2>";     
  33.     return $res;
  34.  }
  35.  
  36.  function Close($con) {
  37.     $con->close();  
  38.  }
  39.  
  40. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  41.  {
  42.        
  43.      $username = $_POST['username'];
  44.          $password = $_POST['password'];
  45.  
  46.          $mysql = Open("catdb");
  47.          $sql = "SELECT ID_Tecnico, Nome, Cognome
  48.                  FROM tecnico
  49.                  WHERE Username= '$username' && Password='$password'";
  50.          $rs = Query($mysql, $sql);
  51.          Close($mysql);
  52.            if ($rs->num_rows == 1) {  
  53.                 $obj = $rs->fetch_object();
  54.                 $_SESSION['id_tecnico'] = $obj->Id_Tecnico;
  55.                 $_SESSION['nome'] = $obj->Nome;
  56.                 $_SESSION['cognome'] = $obj->Cognome;    
  57.                                 header("Location: areariservata.php");            
  58.      }
  59.      else  {  
  60.     echo "<div class='container'>
  61.  
  62.  <div class='login'>
  63.  
  64.     <h1 class='login-heading'>
  65.  
  66.      <strong>Dati errati!</strong> Torna indietro.</h1>
  67.  
  68.     <button class='btn btn--right' onclick='history.back()'> Indietro </button>
  69.  
  70.     </div>
  71. </div>";    
  72. }    
  73.      
  74.  } else
  75.  
  76. echo "
  77.  
  78. <div class='container'>
  79.  
  80.  <div class='login'>
  81.  
  82.     <h1 class='login-heading'>
  83.  
  84.      <strong>Benvenuto.</strong> Autenticati.</h1>
  85.  
  86. <form method='post' action='" . $_SERVER['PHP_SELF'] ."'>
  87.  
  88.        <input type='text' name='username' placeholder='Username' required='required' class='input-txt' />
  89.  
  90.          <input type='password' name='password' placeholder='Password' required='required' class='input-txt' />
  91.        
  92.            <button type='submit' class='btn btn--right'>Entra</button>
  93.    
  94.          </div>
  95.      </form>
  96.  
  97. </div>
  98. </div>";
  99.  
  100. ?>
  101.  
  102.   </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement