[英]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. 我正在尝试使用javascript和cookie。 You guys have any ideas?
你们有什么主意吗? Thanks ahead of time.
提前谢谢。
I need the cookie creation and detection scripts. 我需要cookie创建和检测脚本。 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.
如果您使用javascript构建此功能,则只需禁用javascript,即可允许用户访问您的受保护内容。
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. 为了避免Cookie劫持,您必须使用会话。
php example: php示例:
profile.php - profile.php-
if(isset($_POST["user"]) && isset($_POST["pass"])) { $_SESSION["user"] = $_POST["user"]; }
if(!isset($_SESSION["user"])) { header('Location: index.php'); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.