简体   繁体   中英

How can Javascript redirect a website user back to login page if need be?

If a website user attempts to enter a secure page before entering the login page for the whole website, what script will be able to redirect him back to the login page without hindering his usage of the page normally (after he logged in)?

I am trying to do this with javascript and cookies. You guys have any ideas? Thanks ahead of time.

I need the cookie creation and detection scripts. Thank you.

You will have to handle this on the server-side. If you build this functionality with javascript, simply disabling javascript will allow the user to access your secured content.

Use a server side language for this.

There is no way you must use server-side programming, or your website will become vulnerable.

And to avoid Cookie Hijacking you must use sessions.

php example:

profile.php -

if(isset($_POST["user"]) && isset($_POST["pass"])) { $_SESSION["user"] = $_POST["user"]; }
if(!isset($_SESSION["user"])) { header('Location: index.php'); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM