我知道header('Location: ' . $_SERVER['HTTP_REFERER']);
与它相关的一些安全问题。但是,我需要引导用户回到他来自的页面。只是想了解我是否将用户进入的页面存储在cookie中,并且可能是登录后使用cookie信息将用户重定向回页面?听起来安全吗?喜欢在这里,如果您对我有更好的建议?谢谢你。
有多种方法可以做到这一点。我会在服务器端执行此操作。
例子:
class Page
{
public function define()
{
empty( $_SESSION['SCRIPT_NAME'] ) && $_SESSION['SCRIPT_NAME'] = 'http://example.com'; // default page
in_array( $_SERVER['SCRIPT_NAME'], $this->defined()) && $_SESSION['RECOIL_PAGE'] = $_SERVER['REQUEST_URI']; // if the current page is in allowed list, make it recoil page (let user return to it)
}
public function defined()
{
return array(
'/index.php',
'/categories.php',
'/videos.php',
'/upload.php'
);
}
public function recoil()
{
header( 'Location: ' . $_SESSION['RECOIL_PAGE'] );
exit;
}
}
用法:
$this->page->define();
//要检查是否应将页面设置为允许的值,请反冲页面$this->page->recoil();
//将用户重定向到可能的后坐页面(如果不在列表中),然后重定向到默认页面本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句