在php file_get_contents中获取referer

OPO*_*OPO 7 php url

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

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

在第二个内部,我用这种方式称呼第一个 file_get_contents('www.aaa.com/file.php');

我想www.aaa.com/file.php获得调用它的网站的网址.

可能吗?

www.lol.com电话www.aaa.com/file.php - >它得到www.lol.pl

www.another.com 叫它 - >它得到 www.another.com

像'谁从另一台服务器打电话给我,以及它是什么服务器?'

Jer*_*meJ 16

实际上,不,因为它不像Payalytic上尉所说的那样明显,这里是如何做到的.

$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)); 
Run Code Online (Sandbox Code Playgroud)

资料来源: http ://thuannvn.blogspot.be/2011/12/how-to-set-referer-in-php.html

在对官方文档感到头痛之后,我没有对引用者说一句话,我终于在网上做了经典搜索,并立即发现了这一点.万岁!

编辑:虽然文档说header应该是一个字符串(http://be2.php.net/manual/en/context.http.php).应该检查它是否也适用于数组.

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

你也可以使用curl.


Kna*_*ģis -1

您需要将引用者作为参数传递给file_get_contents

file_get_contents('http://www.aaa.com/file.php?referrer='.urlencode($referrer));
Run Code Online (Sandbox Code Playgroud)

否则第二个服务器不可能获得原始引用者。