如何才能使页面只能从将用户重定向到该页面的页面进行访问?

时间:2015-05-22 15:28:17

标签: php html browser-history

我想让页面只能从重定向到它的页面进行访问。重定向到此页面的此页面称为/purchase.php,然后此页面重定向到一个名为/username.php的页面,我希望此页面只能从/purchase.php访问,而不是直接从URL访问。< / p>

解决方案: 对于purchase.php:

<?php
session_start();
//Put this when the purchase is vailidated
$SESSION_['fromMain'] = "true";
//Then redirect
header ("Location: url.com/username.php");
?>

对于username.php:

<?php
//Check if the browser comes from purchase php
if($_SESSION['fromMain'] == "false"){
//If not redirect to index page
header ("Location: url.com/index.php
} else {
$SESSION_['fromMain'] = "false";
{
?>

1 个答案:

答案 0 :(得分:1)

作为一项额外措施(除了已经由CD001发表的评论),您可以使用$ _SERVER [“HTTP_REFERER”]变量,如果直接从浏览器界面请求脚本,该变量将为空。