How to redirect users to previous page using SESSION and/or COOKIES
Is there a solution recipe for the following:
User logins from main page -> user is redirected to user profile page
if user logins from shop.php page -> users is redirected to previous page
Below is a pieceof code that I found on this forum and works perfect for redirecting users based on their user level. Now I would like to make it redirect to previous page when users do not log in from main page.
<?php
if(!session_id()) session_start();
switch($_SESSION['userLevel']) {
case "1":
header("Location: admin_index.php");
break;
case "2":
header("Location: clients_index.php");
break;
}
?>
The problem that I have is
1) Can the above code have an else if statement to add the third scenario? If so, can you please tell what is wrong with the code below.
<?php
if(!session_id()) session_start();
switch($_SESSION['userLevel']) {
case "1":
header("Location: admin_index.php");
break;
case "2":
header("Location: clients_index.php");
break;
}
else if(!session_id()) session_start();
switch($_SESSION['userLevel']=9) {
case "3":
header("Location: admin_index.php");
}
?>
2) How do I add a SESSION to shop.php page so that Security Assist knows to redirect the user to the previous page and not the control page. I found and added the following code to the shop.php page but no luck. Does Security Assist has a function to add the SESSION to the page or I will have to hand code it allays?
<?php
if (!session_id()) session_start();
if(!isset($_SESSION["userLevel"])) {
$_SESSION["userLevel"] = "9";
}
?>