【发布时间】:2015-08-04 16:55:40
【问题描述】:
我想让一个页面只能从重定向到它的页面访问。这个重定向到这个页面的页面叫做/purchase.php,然后这个页面重定向到一个叫做/username.php的页面,我希望这个页面只能从/purchase.php访问,而不是直接从一个url访问。
解决方案: 购买.php:
<?php
session_start();
//Put this when the purchase is vailidated
$SESSION_['fromMain'] = "true";
//Then redirect
header ("Location: url.com/username.php");
?>
对于用户名.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";
{
?>
【问题讨论】:
-
不要从 PHP 向浏览器输出任何东西,当它完成时只是 HTTP 重定向并且浏览器 不应该 缓存它:你可能只是使用了站点搜索功能虽然:stackoverflow.com/questions/49547/…
标签: php html browser-history