Welcome Back

Sign in to your account

Please enter your email or mobile number
Please enter your password

Don't have an account?

Create Account
php // login.php - COMPLETE FIXED VERSION require_once 'config/database.php'; require_once 'includes/auth.php'; require_once 'includes/functions.php'; // If already logged in, redirect to home if (isLoggedIn()) { if (isAdmin()) { header('Location: admin/dashboard.php'); } else { header('Location: index.php'); } exit(); } $error = ''; $email = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email = trim($_POST['email']); $password = $_POST['password']; $remember = isset($_POST['remember']); if (empty($email) || empty($password)) { $error = 'Please fill in all fields'; } else { try { // Check if user exists with email or mobile $stmt = $pdo->prepare("SELECT * FROM users WHERE (email = ? OR mobile = ?) AND status = 1"); $stmt->execute([$email, $email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { // Set session $_SESSION['user_id'] = $user['id']; $_SESSION['user_name'] = $user['name']; $_SESSION['user_email'] = $user['email']; $_SESSION['user_role'] = $user['role']; // Remember me if ($remember) { setcookie('user_id', $user['id'], time() + 86400 * 30, '/'); setcookie('user_email', $user['email'], time() + 86400 * 30, '/'); } // Redirect based on role if ($user['role'] === 'admin') { header('Location: admin/dashboard.php'); } else { header('Location: index.php'); } exit(); } else { $error = 'Invalid email/mobile or password'; } } catch (PDOException $e) { $error = 'Login failed. Please try again.'; // For debugging (remove in production): // $error = 'Database error: ' . $e->getMessage(); } } } include 'includes/header.php'; ?>

Welcome Back

Sign in to your account

Please enter your email or mobile number
Please enter your password
Forgot Password?

Don't have an account?

Create Account
php // login.php require_once 'config/database.php'; require_once 'includes/auth.php'; if (isLoggedIn()) { header('Location: index.php'); exit(); } $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email = trim($_POST['email']); $password = $_POST['password']; $remember = isset($_POST['remember']); if (empty($email) || empty($password)) { $error = 'Please fill in all fields'; } else { $stmt = $pdo->prepare("SELECT * FROM users WHERE (email = ? OR mobile = ?) AND status = 1"); $stmt->execute([$email, $email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['user_name'] = $user['name']; $_SESSION['user_email'] = $user['email']; $_SESSION['user_role'] = $user['role']; if ($remember) { // Set cookie for 30 days setcookie('user_id', $user['id'], time() + 86400 * 30, '/'); } if ($user['role'] === 'admin') { header('Location: admin/dashboard.php'); } else { header('Location: index.php'); } exit(); } else { $error = 'Invalid email/mobile or password'; } } } include 'includes/header.php'; ?>

Login


Forgot Password?

Don't have an account? Register Now