Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!empty($_POST['login-submit']))
- {
- $email=$_POST['email'];
- $pass=$_POST['pass'];
- $servername="localhost";
- $username="root";
- //create connection
- $conn=new mysqli($servername,$username,"","projectdb");
- if($conn->connect_error)
- {
- echo "Failed due to ".$conn->connect_error;
- }
- else {
- //check if the user exists
- $check = "select * from users where email='".$email."'";
- if ($result = $conn->query($check)) {
- if ($result->num_rows > 0)
- {
- $row=$result->fetch_assoc();
- if($row['password']==$pass)
- {
- //CREATING LOGIN COOKIE THAT EXPIRES IN 30 MINUTES
- $cookie_name = "videosharing_user";
- $cookie_value = $row['name'];
- $cookie_name2= "videosharing_user_email";
- $cookie_value2=$row['email'];
- setcookie($cookie_name, $cookie_value, time() + (60*30), "/");
- setcookie($cookie_name2, $cookie_value2, time() + (60*30), "/");
- //header("Location:login.html",TRUE);
- echo 'Successfully logged in. <a href="login.html">CLICK HERE</a>';
- }
- else
- {
- echo 'Wrong Password! TRY AGAIN <a href="index.php">CLICK HERE</a>';
- }
- }
- else
- {
- echo "No such user exists";
- }
- } else {
- echo "Unknown error occurred";
- }
- }
- $conn->close();
- }
Add Comment
Please, Sign In to add comment