Vote count:
0
I am trying to make user authentication but don't know i can't logged in and in way of not logged in its redirected to index page but index page is missing style sheet after login failure. Here is the code(I used PDO method)
try {
$cnx = new PDO("mysql:host=$hostname; dbname=$database",
$username, $password);
$cnx -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$email = $_POST['email'];
$password = $_POST['password'];
$stmt = $cnx -> prepare("SELECT email, password FROM tbl_user
WHERE email = '".$email."' and password = '".$password."'");
$stmt -> bindParam('".$email."', $email, PDO::PARAM_STR);
$stmt -> bindParam('".$password."', $password, PDO::PARAM_STR);
$stmt -> EXECUTE();
$em = $stmt -> fetchColumn();
if ($em == true) {
session_register("email");
session_register("password");
$_SESSION['email'] = $_POST['email'];
$_SESSION['START'] = time();
setcookie("username", $_POST['email'], mktime()+(60*3),
"/");
setcookie("LUS", time(), mktime()+(60*3), "/");
$stmt -> $cnx -> prepare("SELECT email FROM tbl_user WHERE
email = '".$email."'");
$stmt -> EXECUTE();
$em2 = $stmt -> fetchColumn();
echo "Logged in.";
} else {
echo "Email or password is incorrect.";
}
} catch (Exception $e) {
echo "".$e->getMessage();
}
} elseif (empty($_POST['email']) &&
!empty($_POST['password'])) {
echo "<font color='red'> Error : Enter your email.</font>";
} elseif (!empty($_POST['email']) &&
empty($_POST['password'])) {
echo "<font color='red'> Error : Enter your password.
</font>";
} else {
echo "<font color='red'> Error : Enter your email &
password.</font>";
}
}
elseif (isset($_SESSION['email'])) {
// include ('../users/index.');
echo "worked";
}
elseif (!isset($_SESSION['email'])) {
include ('../index.php');
}
?>
asked 56 secs ago
please check this code for errors
Aucun commentaire:
Enregistrer un commentaire