简体   繁体   English

如果会话过期或页面需要登录,则重定向到自定义URL

[英]redirecting to custom url if session expires or if a page requires login

all of our users have custom urls. 我们所有的用户都有自定义网址。 user.domain.com. user.domain.com。 when a session expires, the page gets routed to index.php. 当会话过期时,页面将路由到index.php。 I need it to require it to redirect to user.domain.com so that they can login from that page. 我需要它来重定向到user.domain.com,以便他们可以从该页面登录。 The problem is how can i capture that information to redirect to the custom url. 问题是我如何捕获该信息以重定向到自定义URL。 Also, let say that sombody tries to go to user.domain.com/home.php but it requires login. 另外,假设某人试图转到user.domain.com/home.php,但需要登录。 How can i redirect for it login at user.domain.home.php 我如何重定向它登录user.domain.home.php

Thanks! 谢谢!

You should simply include a php script in every page, above the code. 您应该在代码上方的每个页面中简单地包含一个php脚本。 such as: 如:

include('auth.php');

That should check if the login is correct using the session variables. 那应该使用会话变量检查登录是否正确。 If it's not correct, destroy the currect session login information (to be sure) and redirect the user to the login form... 如果不正确,请销毁当前会话的登录信息(确定),然后将用户重定向到登录表单...

header("Location: login.php");

That's a fast response. 这是一个快速的反应。

Your question does not sound very clear to me. 您的问题对我来说不太清楚。 Anyway, concerning the second part of your question, you can simply do something like this: 无论如何,关于问题的第二部分,您可以简单地执行以下操作:

<?
session_start();
if($_SESSION["logged"]!=1 or !isset($_SESSION["logged"])) 
header("Location: loginPage.php");
?>

does this answer your question? 这回答了你的问题了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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