PHP - Referer重定向脚本

10 php http-referer

通常,在搜索答案时,我发现某些网站会允许您阅读他们提供的信息(例如,引用者是google.com).但是,如果您直接链接到信息,它将无法使用.

我正在寻找的是最小的PHP脚本,它将设置我选择的引用者和目的地,如下所示:

http://example.com/ref_red.php?referer=http://google.com/&end=http://example.net/
Run Code Online (Sandbox Code Playgroud)

笔记:

  • ref_red.php是我的示例中脚本的名称.
  • refererend应该接受http,https,ftp.
  • refererend可以包含任何类型的URI,例如http://end.com这样简单,或者像以下一样复杂: http://example.com/some/rr/print.pl?document=rr.

注意:根据回复中的建议,我添加此内容.该脚本本身不是完整的代理.仅最初的HTTP请求将被代理的(如图像等不后续请求)唯一目的设置的引用者.

bum*_*box 12

这个函数应该给你一个起点,它将使用指定的referrer获取任何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; 
    } 

?>
Run Code Online (Sandbox Code Playgroud)