Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (isset($_SESSION["logged_in"]))
- {
- header("Location: home.php");
- }
- $username=$_POST["username"];
- $password=$_POST["password"];
- // encrypt in MD5 and compare what's on the database
- $password=md5($password);
- $db = new PDO('mysql:host=127.0.0.1;dbname=dropbin;charset=utf8', '', '');
- $stmt = $db->query("SELECT * FROM user where username='$username' and password='$password'");
- echo "you are using $username and password $password<br>";
- $authenticated=true;
- if($stmt)
- {
- $authenticated=false;
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- echo "First Name: ". $row['first_name']. " <br> last name is: ". $row['last_name'] ." <br>Email: ".$row["email"];
- $_SESSION["logged_in"]=true;
- $_SESSION["username"]=$row["username"];
- $_SESSION["first_name"]=$row["first_name"];
- $_SESSION["last_name"]=$row["last_name"];
- $_SESSION["email"]=$row["email"];
- $_SESSION["user_id"]=$row["id"];
- //forward to home page
- header("Location: home.php");
- }
- }
- if(!$authenticated)
- echo "Sorry wrong username and password";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement