简体   繁体   English

如果需要,JavaScript如何将网站用户重定向回登录页面?

[英]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.

相关问题 如何设置javascript重定向以将用户发送到后台? 看代码 - How to setup javascript redirect to send user to back page? see code 如何将用户重定向到登录页面 - how to redirect user to login page with PHP 文件中的 Javascript 警报 - 在警报通知用户凭据失败后,尝试使其重定向回登录页面 - Javascript Alert in PHP file -- trying to get it to redirect back to login page after alert notifies user of failed credentials 如何将用户从没有html / view的页面重定向回去? - How can I redirect a user back from a page with no html/view? 使用javascript将用户重定向到Liferay登录页面 - Redirect user to liferay login page using javascript 如何将用户登录到外部页面并将用户重定向到那里? - How to login the user to an external page and redirect the user there? 将用户重定向到登录页面 - redirect user to login page 如果我的网站页面在浏览器窗口中失去焦点,如何将用户重定向到 Javascript/jQuery 中的页面? - How to redirect user to a page in Javascript/jQuery if my website page gets out of focus in the browser window? 如何在javascript中强制重定向到登录页面 - how to force redirect to login page in javascript 用户单击 JavaScript 中的浏览器后退按钮后如何将用户重定向到另一个页面 - How to redirect user to another page once he has clicked the browser back button in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM