Guest User

login.php

a guest
Jan 9th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. require('basededonnees.php');
  4.  
  5. $login = $_POST['login'];
  6. $password =$_POST['password'];
  7.  
  8.  
  9. if (!empty($user) && !empty($password)){
  10.    
  11.     $req = $connect->prepare('SELECT id,user,password,nom,prenom,age,prof FROM user WHERE user=:user AND password=:password');
  12.     $req->execute(array('user' => $user,'password' => md5($password)));
  13.     $resultat = $req->fetch(PDO::FETCH_ASSOC);
  14.     $req->closeCursor();
  15.    
  16.     if ($resultat){
  17.             echo'Erreur connexion';
  18.             exit();
  19.            
  20.         }
  21.    
  22.     else{  
  23.         session_start();
  24.         $_SESSION['id'] = $resultat['id'];
  25.         $_SESSION['user'] = $user;
  26.         $_SESSION['nom']=$resultat['nom'];
  27.         $_SESSION['prenom']= $resultat['prenom'];
  28.         $_SESSION['prof']=$resultat['prof'];
  29.        
  30.         if($_SESSION['prof']==1){
  31.             header('Location: /acces-prof/index.php');
  32.             exit();
  33.         }
  34.        
  35.         if($_SESSION['prof']==0){
  36.             header('Location: /acces-eleves/index.php');
  37.             exit();
  38.         }
  39.            
  40.         }
  41. }
  42.  
  43. else {
  44.     header('Location: ../index.php?erreur=1');
  45.     exit();
  46. }
  47. ?>
Add Comment
Please, Sign In to add comment