Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取php文件中的引用\u获取\u内容_Php_Url - Fatal编程技术网

获取php文件中的引用\u获取\u内容

获取php文件中的引用\u获取\u内容,php,url,Php,Url,我在www.aaa.com/file.php上有一些文件 我在www.saveme.com/file2.php上有另一个文件 在第二个文件中,我用这种方式称第一个为file\u get\u contents('www.aaa.com/file.php') 我想www.aaa.com/file.php获取调用它的站点的url 可能吗 www.lol.com调用www.aaa.com/file.php->它得到www.lol.pl www.other.com调用它->它得到www.other.com

我在
www.aaa.com/file.php上有一些文件

我在
www.saveme.com/file2.php上有另一个文件

在第二个文件中,我用这种方式称第一个为
file\u get\u contents('www.aaa.com/file.php')

我想
www.aaa.com/file.php
获取调用它的站点的url

可能吗

www.lol.com
调用
www.aaa.com/file.php
->它得到
www.lol.pl

www.other.com
调用它->它得到
www.other.com


类似于“谁从另一台服务器呼叫了我,是哪台服务器?”

您需要将referer作为参数传递给
file\u get\u contents

file_get_contents('http://www.aaa.com/file.php?referrer='.urlencode($referrer));

第二台服务器不可能以其他方式获取原始引用人。

请查看您将在何处找到有关get_header()和$http_response_header的信息。

事实上,没有,因为它不像Payalysis队长所说的那么明显,下面是如何做到这一点

$referer = "http://abc.info";
$opts = array(
       'http'=>array(
           'header'=>array("Referer: $referer\r\n")
       )
);
$context = stream_context_create($opts);
file_put_contents($img, file_get_contents($node_img, false, $context)); 
来源:

在对官方文件感到头痛之后,我没有说一句关于推荐人的话,最后我在网上做了一个经典的搜索,并立即找到了这个。万岁

编辑:文档说
标题应该是字符串()。我们应该检查它是否也适用于数组

或者,您还应该能够从收到的请求的IP检索域名。(但并不总是如此)


您也可以使用
curl

是的,因为file\u get\u contents启动了一个新的HTTP会话,它无法继承原始的引用程序。此代码不能作为一般解决方案使用。(此代码仅在您同时控制源URL和目标URL时有效。)JeromeJ提供的解决方案适用于所有情况。我需要确定如果引用者与站点的域不同,站点是否允许您访问那里的图像。JeromeJ的代码使我能够做到这一点。响应edit:header可以作为数组或字符串。(我测试了两种方法。)作为字符串,您可以键入
'header'=>“Referer:$Referer\r\n”
,它比数组代码略短。