Advertisement
Ed_

ed

Ed_
Feb 19th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?
  2.  
  3. @session_start();
  4. $sql = array('username', 'password', 'mydb', '127.0.0.1');
  5.  
  6. try{
  7.     $pdo = new PDO('mysql:host='.$sql[3].';dbname='.$sql[2], $sql[0], $sql[1], array(PDO::ATTR_PERSISTENT=>true));
  8.     if(!isset($_POST['username_email'])){ throw new Exception('Nav e-pasts :('); }
  9.     if(!isset($_POST['password'])){ throw new Exception('Nav paroles :('); }
  10.  
  11.     $db = $pdo->prepare('SELECT `id` FROM `users` WHERE (`username`=:mail OR `email`=:mail) and `password`=:pw');
  12.     $db->bindParam(':mail', $_POST['username_email']);
  13.     $db->bindParam(':pw', $_POST['password']);
  14.     $db->execute();
  15.     if(!$u = $db->fetch(PDO::FETCH_OBJ)){ throw new Exception(':( Lol, not found.'); }
  16.  
  17.     $_SESSION['login'] = 1;
  18.     $_SESSION['my_id'] = $u->id;
  19. }catch(PDOException $e){
  20.     die("PDO Error!: " . $e->getMessage() . "<br/>");
  21. }catch(Exception $e){
  22.     die("Error!: " . $e->getMessage() . "<br/>");
  23. }
  24.  
  25. if($_SESSION['login']){
  26.     Header('Location: '.$DEFAULT_LINK);
  27.     exit;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement