I am working on local machine on a projet and i want to redirect user back to their previous after they have logged in.I tried myself based on research over internet, but no success. If somebody could help; will appreciate…Here are my code.
sell.php
[php]if (!isset($_SESSION[“user_id”])) {
header(“Location: login.inc.php?location=”. urlencode($_SERVER[“REQUEST_URI”]));
exit();
}
include_once("./includes/partheader.html");[/php]
login.inc.php
[php]
Email : ' /><?php if(isset($errEmail) ){echo $errEmail;} ?>
Mot de passe : <?php if(isset($pwdErr)){ echo $pwdErr;} ?>
">
[/php] [b]login_form.inc.php[/b] [php]if(array_key_exists('login', $_POST)){ $redirect = NULL; if($_POST['location'] != '') { $redirect = $_POST['location']; }
if (empty($_POST["email"])) {
$errEmail = "Enter your email";
} else {
$email = trim($_POST[“email”]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errEmail = "Invalid email ";
}
}
if (empty($_POST[‘userpwd’])) {
$pwdErr = “Entrer votre mot de passe”;
}
else{
$userpwd = sha1($_POST[‘userpwd’]).$_POST[‘userpwd’];
}
if(empty($errEmail) && empty($pwdErr) ){
include_once(BASE_URI.“pdoconnect.inc.php”);
if(isset($pdo) ){
try{
$sql = ‘SELECT userid, gender,nameuser FROM users WHERE users.email = :email AND users.userpwd = :userpwd’;
$stmt = $pdo->prepare($sql);
$stmt->bindValue(’:email’, $email);
$stmt->bindValue(’:userpwd’, $userpwd);
$stmt->execute();
$rowscount = $stmt->rowCount();
if(isset($rowscount) && $rowscount < 1 ){
$err = 'Mot de passe ou nom d\' utilisateur incorrect';
}
else{
foreach($result = $stmt->fetchAll() as $row){
$_SESSION['user_id'] = $row['userid'];
$_SESSION['gender'] = $row['gender'];
$_SESSION['nameuser'] = $row['nameuser'];
} //end foreach
if (isset($redirect)) {
header("Location:". $redirect);
}
//end of redirect header
}
}catch (PDOException $e) {
$errors[] = “Eror in script”.$e->getMessage();
}
}
}//end of check error
}//end of post
[/php]
My issue is when i fill the login form with the right details…the page should redirect to sell.php instead it stays on the login page with this url in browser [php]:http://localhost/projet-fembuleuse/html/login.inc.php?location=%2Fprojet-fembuleuse%2Fhtml%2Fvendre.php[/php]