close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

How to redirect users to previous page using SESSION and/or COOKIES

Thread began 4/27/2012 3:17 pm by danny405167 | Last modified 4/30/2012 6:42 am by danny405167 | 5801 views | 1 replies

Jason ByrnesWebAssist

1) This code uses the switch case concept. You cannot add an else statement to the switch .. case.


think of it as a switchboard.


the switch statement sets a variable to be used for comparison. the case statement sets an action to be performed if the comparison variables matches the case value.

the code:

php:
switch($_SESSION['userLevel']) { 

    case "1": 
        header("Location: admin_index.php"); 
        break; 
    case "2": 
        header("Location: clients_index.php"); 
        break; 
}



could also be written using if... else, but switch... case is more efficient:

php:
<?php

if($_SESSION['userLevel'] == "1") {
    
header("Location: admin_index.php"); 
} elseif(
$_SESSION['userLevel'] == "2") {
    
header("Location: clients_index.php"); 
}
?>




to add a third scenario to the switch... case code, you just need to add another case statement:

php:
switch($_SESSION['userLevel']) { 

    case "1": 
        header("Location: admin_index.php"); 
        break; 
    case "2": 
        header("Location: clients_index.php"); 
        break; 
    case "3": 
        header("Location: admin_index.php"); 
        break; 
}




2) Redirecting back to the previous page is not done using a session variable. when you access a proteced page, it redirects to the login page with a querystring varaible that contains the path to the protected page named "accesscheck":
users_login.php?accesscheck=%2Fsculptortocms%2Fadmin_cms%2Findex.php%3F

just make sure that the action of the login form on the login page is set to pass any existing querystreing variables by using this code for the action attribute:

php:
 action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".htmlspecialchars($_SERVER["QUERY_STRING"]):""?>"

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...