Php 仅从域访问的标题

Php 仅从域访问的标题,php,Php,我的一个网页中有这个test.php代码 <?php ob_start(); $links = array( 'dolhd' => '/dohd.m3u8', 'dol1' => '/dol1.m3u8', 'dol2' => '/dol2.m3u8', 'dol3' => '/dol3.m3u8', 'thd' => '/thd.m3u8', 't1' => '/t1.m3u8', 'test'

我的一个网页中有这个test.php代码

<?php
ob_start();
$links = array(
    'dolhd' => '/dohd.m3u8',
    'dol1' => '/dol1.m3u8',
    'dol2' => '/dol2.m3u8',
    'dol3' => '/dol3.m3u8',
    'thd' => '/thd.m3u8',
    't1' => '/t1.m3u8',
    'test' => 'https://www.youtube.com/watch?v=0OWt8O8pgw0',
);

$id = $_GET['id'] ? ($links[$_GET['id']] ? $_GET['id']: 'test') : 'test';
header ('Location:'.$links[$id]);
ob_flush();
exit;
?>

该页面通过浏览器访问,如下所示
test.php?id=dol1
,结果是下载文件dol1.m3u8

我想知道是否有可能只从同一域的另一个页面访问该页面


或阻止除域之外的所有ip-s的访问。

放入重定向的文件头并更改您的ip地址:

<?php
$allow = array("192.168.10.1", "192.168.10.2", "192.168.10.3");

if (!in_array($_SERVER['REMOTE_ADDR'], $allow)) {
   echo "Your access denied!";
   exit();
} 
?>


只需确保将“your.domain.here”替换为域所需的字符串即可。此处的更多信息->

您可以仅通过引用
$\u SERVER['REMOTE\u ADDR']
中的特定IP地址来限制通过域的IP访问此页面-这是最可靠的选择。您不能这样做。。。因为谁应该打开那个链接?你的域名是谁的?不,你不能依赖于
HTTP\u REFERER
值的安全性,因为它是由客户端发送的-因此,当我输入地址时可能是伪造的,它工作正常。但是当我从另一个页面上做一个请求时,它也不起作用。那不好!回显http_referer的输出,并使用相同的格式检查您的输出。我敢打赌,在安全方面有更好的方法,但在找到更有效的解决方案之前,这将适用于原型/测试。
if ($_SERVER["HTTP_REFERER"]!=="your.domain.here"){
//redirect or whatever - referrering url not from this domain
            }else{
ob_start();
$links = array(
    'dolhd' => '/dohd.m3u8',
    'dol1' => '/dol1.m3u8',
    'dol2' => '/dol2.m3u8',
    'dol3' => '/dol3.m3u8',
    'thd' => '/thd.m3u8',
    't1' => '/t1.m3u8',
    'test' => 'https://www.youtube.com/watch?v=0OWt8O8pgw0',
);

$id = $_GET['id'] ? ($links[$_GET['id']] ? $_GET['id']: 'test') : 'test';
header ('Location:'.$links[$id]);
ob_flush();
exit;
}