Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form class="form-inline" action="../includes/login.php" method="post">
- <input type="text" name="email" class="form-control mr-2" placeholder="Username/Email">
- <input type="password" name="password" class="form-control mr-2" placeholder="Password">
- <input type="submit" name="login-submit" class="btn btn-primary mr-2" value="Login">
- </form>
- <a href="singup.php" class="btn btn-info mr-2">Signup</a>
- if (isset($_POST['login-submit'])) {
- $email = $_POST['email'];
- $password = $_POST['password'];
- if (empty($email) || empty($password)) {
- header("Location: ../public/index.php?error=emptyfields");
- exit();
- } else {
- $conn = mysqli_connect("localhost", "root", "", "expodb");
- $sql = "SELECT * FROM users WHERE username=? OR email=?;";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../public/index.php?error=sqlerror");
- exit();
- } else {
- mysqli_stmt_bind_param($stmt, "ss", $email, $email);
- mysqli_stmt_execute($stmt);
- $result = mysqli_stmt_get_result($stmt);
- if ($row = mysqli_fetch_assoc($result)) {
- $passwordCheck = password_verify($password, $row['password']);
- if ($passwordCheck == false) {
- header("Location: ../public/index.php?error=wrongpassword");
- exit();
- } elseif ($passwordCheck == true) {
- session_start();
- }
- } else {
- header("Location: ../public/index.php?error=nouser");
- exit();
- }
- }
- }
- } else {
- header("Location: ../public/index.php");
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement