简体   繁体   中英

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

all of our users have custom urls. user.domain.com. when a session expires, the page gets routed to index.php. I need it to require it to redirect to user.domain.com so that they can login from that page. The problem is how can i capture that information to redirect to the custom url. Also, let say that sombody tries to go to user.domain.com/home.php but it requires login. How can i redirect for it login at user.domain.home.php

Thanks!

You should simply include a php script in every page, above the code. 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?

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