Advertisement
Guest User

dbConnecterController.php

a guest
Mar 31st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. namespace App\Controller;
  3. use PDO;
  4.  
  5. class dbConnecterController {
  6.     public function __construct(){
  7.     }
  8.  
  9.     public  function validate(){
  10.         $username = $_POST['username'];
  11.         $password = $_POST['password'];
  12.  
  13.         $host = "localhost";
  14.         $user = "root";
  15.         $pass = "";
  16.         //$pass = "toor";
  17.         $dbname = "MyGalleryDb";
  18.         //$dbname = "mygallerydb";
  19.  
  20.  
  21.         // Handle a bit of connection errors
  22.         try {
  23.             // Connect to server via PHP Data Object
  24.             $dbconnection = new PDO('mysql:host='.$host.';dbname=' . $dbname, $user, $pass);
  25.  
  26.  
  27.  
  28.         } catch (PDOException $e) {
  29.             echo htmlentities($e);
  30.             die();
  31.             echo "FAIL!";
  32.         }
  33.  
  34.             $result = $dbconnection->query('SELECT * FROM users WHERE username="'.$username.'" && password ="'.$password.'";');
  35.             $result->setFetchMode(PDO::FETCH_ASSOC);
  36.             //$row = $result->fetch();
  37.  
  38.             if ($username && $password) {
  39.                 $row = $result->fetchColumn();
  40.                 if($row != 0){
  41.                     while ($result->fetchColumn) {
  42.                         $usernameDb = $info['username'];
  43.                         $passwordDb = $info['password'];
  44.  
  45.                         if ($username == $usernameDb && $password == $passwordDb) {
  46.                             header('Location: gallery.php');
  47.                             $_SESSION['username'] = $usernameDb;
  48.                         } else {
  49.                             die("You messed up maaan... Check your username or password.");
  50.                         }
  51.                     }
  52.                 } else {
  53.                     die("Username not in the DB, talk with the owner to add you!");
  54.                 }
  55.             }
  56.         }
  57.     }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement