Advertisement
Guest User

My whole PHP file

a guest
Apr 21st, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.         function Login() {
  3.             $success = false;  
  4.             $usr = "XXX";
  5.             $psw = "XXX";
  6.             alert("HELLOOOOO");
  7.             try {
  8.                 $con = new PDO( 'mysql:host=localhost;dbname=exalumnes', $usr, $psw );
  9.                 $sql = "SELECT * FROM Usuaris WHERE NomUsuari = :username AND Password = :password LIMIT 1";
  10.                                       //users       //username
  11.  
  12.                 alert($sql);
  13.  
  14.                 $stmt = $con->prepare( $sql );
  15.  
  16.                 $stmt->execute(array(':username'=>$_POST['username'], ':password'=>$_POST['password']));
  17.  
  18.                 $valid = $stmt->fetchColumn();
  19.  
  20.                 if( $valid ) {
  21.                     $success = true;
  22.                     session_start();
  23.                     session_regenerate_id();
  24.                     $_SESSION['user'] = $_POST['username'];
  25.                     session_write_close();
  26.                     echo ('CORRECTO');
  27.                     exit();
  28.                 }
  29.  
  30.                 $con = null;
  31.                 return $success;
  32.             }
  33.             catch (PDOException $e) {
  34.                 echo $e->getMessage();
  35.                 return $success;
  36.             }
  37.         }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement