Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - login.php
- <?php
- session_start();
- if(isset($_POST['login'], $_POST['password'], $_POST['password2'])) {
- if($_POST['password']==$_POST['password2']) {
- try {
- define("DBTYPE", "mysql");
- define("DBHOST", "localhost");
- define("DBNAME", "lab12");
- define("DBUSER", "root");
- define("DBPASS", "root");
- $db = new PDO(DBTYPE . ':host=' . DBHOST . ';dbname=' . DBNAME,DBUSER,DBPASS);
- $name = $_POST['login'];
- $pass = $_POST['password'];
- $db -> exec("USE lab12");
- $query = "SELECT * FROM users WHERE login=:name";
- $prep = $db->prepare($query);
- $prep->bindParam(':name',$name);
- $prep->execute();
- if($prep->rowCount()!=0) {
- $res = $prep->fetch();
- if($res[2]==$pass) {
- $_COOKIE['name'] = $name;
- $_COOKIE['pass'] = $pass;
- $_COOKIE['signedin'] = true;
- } else {
- $_SESSION['error'] = true;
- $_SESSION['err_type'] = "Wrong password.";
- header('Location: signin.php');
- exit;
- }
- } else {
- $_SESSION['error'] = true;
- $_SESSION['err_type'] = "User not found.";
- header('Location: index.php');
- exit;
- }
- } catch (PDOException $e) {
- $_SESSION['error'] = true;
- $_SESSION['err_type'] = "Unsuccessful SQL transaction. Please try again later.";
- header('Location: index.php');
- exit;
- }
- } else {
- $_SESSION['error'] = true;
- $_SESSION['err_type'] = "Passwords do not match.";
- header('Location: index.php');
- exit;
- }
- } else {
- $_SESSION['error'] = true;
- $_SESSION['err_type'] = "Please try again.";
- header('Location: signin.php');
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement