开发者

How to return user back to the page where he came from, after successful logout?

How to return user back to the page where he came from, after successful logout? My logout function looks like that.

function logout()
{
global $db;
session_start();

if(isset($_SESSION['id']) || isset($_COOKIE['id'])) {
$db->query("update `users` 
            set `ckey`= '', `ctime`= '' 
            where `id`='$_SESSION[id]' OR  `id` = '$_COOKIE[id]'") or die($db->error);
}           

/************ Delete the sessions****************/
unset($_SESSION['id']);
unset($_SESSION['login']);
unset($_SESSION['level']);
unset($_SESSION['HTTP_USER_AGEN开发者_如何学运维T']);
session_unset();
session_destroy(); 

/* Delete the cookies*******************/
setcookie("id", '', time()-60*60*24*COOKIE_TIME_OUT, "/");
setcookie("login", '', time()-60*60*24*COOKIE_TIME_OUT, "/");
setcookie("key", '', time()-60*60*24*COOKIE_TIME_OUT, "/");

header("Location: ????");
}


When you load all your views you can append the current URL to the logout link

logout.php?return=/page/param

Then when you logout, you can check $_GET['return'] and redirect there.

You could fall back on $_SERVER['HTTP_REFERER'] (because it can be edited), and finally on failure just redirect to your home page.


It's not perfect but you can use $_SERVER['HTTP_REFERER'] to get the page URI from where the user clicked on the "logout" link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜