使页面只可用彻底重定向,而不是直接url

Make Page available only thorough redirect and not by direct url

本文关键字:url 重定向      更新时间:2023-09-26

我有一些网页,我想只通过内部重定向出现,这样即使有人只是在url中键入他们不会通过。要查看它们,您需要通过重定向到"安全页面"的页面。

你可以在$_SERVER超全局变量中使用HTTP_REFERER。

在限制页的顶部:

<?php
// if the referrer is not the page you want the traffic coming from (http://yourdomain.com/allowed_from_page.php), redirect back to that page.
if($_SERVER['HTTP_REFERER'] !== 'http://yourdomain.com/allowed_from_page.php')
    header('Location: http://yourdomain.com/allowed_from_page.php');

将此添加到将重定向到指定页面的页面:

<form action="./redirectedpage.php" method="POST">
<input type="hidden" name="protection" value="yes"/>
<input type="submit" value="Go to Protected Page">
</form>

将此添加到不能直接访问的页面:

<?php
$unlock = $_POST['protection'];
if ($unlock == 'yes'){
?>
**:: YOUR CODE GOES HERE ::**

<?php
} // END OF THE LOCK CODE
else {
// REDIRECTS USER TO HOME IF HE IS NOT UNLOCKED or IF HE ACCESS THE PAGE DIRECTLY
header('Location: http://myhomepage.com/index.php');
}
?>

请记住,这是一个简单的例子,没有使用会话和类似的东西。如果你需要更多的"安全"你将需要使用,SCAPE($unlock = mysql_real_escape_string($_POST['protection']);),和其他安全的东西。如果有什么不明白的,请告诉我。