Hi;
I am trying to redirect user back to where he was after logged in?i haved tried the code below but it is not working…can somebody subject the rigth way?
[php]<?php
session_start();
if (!isset($_SESSION[‘cart’])) {
$_SESSION[‘cart’] = array();
}
if (isset($_SESSION[‘user_id’]) && filter_var($_SESSION[‘user_id’], FILTER_VALIDATE_INT,array(‘min_range’ => 1)) ) {
header(‘Location:accueil.html.php’);
}
if (array_key_exists(‘login’, $_POST)) {
$email=$pass="";
$errors = array();
// Check for an email address:
if (filter_var($_POST[‘email’], FILTER_VALIDATE_EMAIL)) {
$email = trim($_POST[‘email’]);
} else {
$errorEmail =“Entrer un email valide”;
}
if (empty($_POST[‘pass’])) {
$errorPass = “Entrer votre mot de passe”;
}
else{
$pass = trim($_POST[‘pass’]);
}
if ( $email && $pass) { //All IS GUD
include(‘includes/connect.inc.php’);
try {
$sql = “SELECT user_id FROM registered_user WHERE email = :email AND pass = :pass”;
$stmt = $conn->prepare($sql);
$stmt->bindValue(’:email’, $email);
$stmt->bindValue(’:pass’, SHA1($pass));
$stmt->execute();
$numRows = $stmt->rowCount();
if ($numRows === 1) { //email and pwd combination is rigth
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$_SESSION[‘user_id’] = $row[‘user_id’];
header('Location: '.$_SERVER[‘REQUEST_URI’]);
exit();
}
else{
$errors[] = “Nom d’utilisateur et/ou mot de passe incorrect(s)”;
}
} catch (PDOException $e) {
$systemErr = “Désolé, Erreur de system”.$e->getMessage();
}
} else{
$errors[] = “Désolé, votre connexion a échoué”;
}
}//END MAIN IF
?>[/php]