通常,在搜索答案时,我发现如果引用者是 google.com,某些网站将允许您阅读它们提供的信息。但是,如果您直接链接到该信息,则该信息将不可用。
我正在寻找的是最小的 PHP 脚本,它将设置我选择的引荐来源网址和目的地,如下所示:
http://example.com/ref_red.php?referer=http://google.com/&end=http://example.net/
注意事项:
- ref_red.php 是我示例中脚本的名称。
- referer 和 end 应该接受 http、https、ftp。
- referer 和 end 可以包含任何类型的 URI,简单到 http://end.com或者像这样复杂:
http://example.com/some/rr/print.pl?document=rr
,例如。
注意:根据回复中的建议,我添加了这个。该脚本本身并不是一个完整的代理。 只有初始 HTTP 请求会被代理(不是图像等后续请求)用于设置referer的唯一目的。
最佳答案
这个函数应该给你一个起点 它将使用指定的引荐来源网址获取任何 http url
处理查询参数应该是非常简单的,所以我会把那部分留给你去做
<?php
echo geturl('http://some-url', 'http://referring-url');
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
?>
关于PHP - Referer 重定向脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/857427/