Anti-hotlinking
Forged referer instance code is mainly used to break through anti-leeching, such as pictures, software, etc.
The complete program will be given directly here. You can modify it yourself for specific applications.
The example I give here is very simple. In fact, many applications can be developed from this example. For example, hiding the real URL address... Hehe, just analyze it yourself
Create a new file file.php here. The following parameter is the target address of the referfer that needs to be forged. Such as: file.php/http://www.xxx.xxx/xxx.mp3
Code:
-
- $url=str_replace('/file.php/','',$_SERVER["REQUEST_URI"]);
- $downfile=str_replace(" ", "%20",$url);
- $downfile=str_replace("http://" ,"",$downfile);//Remove http://
- $urlarr=explode("/",$downfile);
- $domain=$urlarr[0];
- $getfile=str_replace($urlarr[0], '',$downfile);
- $content = @fsockopen("$domain", 80, $errno, $errstr, 12);
- if (!$content){
- die("Sorry, unable to connect to $domain .");
- }
- fputs($content, "GET $getfile HTTP/1.0rn" );
- fputs($content, "Host: $domainrn" );
- fputs($content, "Referer: $domainrn" );
- fputs($content, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");
- while (!feof($content)) {
- $tp.=fgets($content, 128) ;
- if (strstr($tp,"200 OK")){
- header("Location:$url");
- die();
- }
- }
-
- $arr=explode("n",$tp);
- $arr1=explode("Location: ",$tp);
- $arr2=explode("n",$arr1[1]);
- header('Content-Type:application/force-download');
- header("location:".$arr2[0]);
- die();
- ?>
The above code can only be used for the anti-hotlinking system that uses referer to determine whether it is hotlinked. It is not applicable to the anti-hotlinking system that uses other special methods to prevent hotlinking.
- $txt=$_GET['url'];
- echo referfile($txt,'http://www.jbxue.com/');
-
-
- function referfile($url,$refer='') {
- $opt=array('http'=>array('header'=>"Referer:$refer"));
- $context=stream_context_create($opt);
- Header("Location:".$url);
- return file_get_contents($url,false,$context);
- }
-
- $host = "pakey.net";
- $target = "/test.asp";
- $referer = "http//uuwar.com/"; //伪造来路页面
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if(!$fp){
- echo "$errstr($errno)
n";
- }else{
- $out = "
- GET $target HTTP/1.1
- Host: $host
- Referer: $referer
- Connection: Closernrn";
-
-
- fwrite($fp, $out);
- while(!feof($fp)){
- echo fgets($fp, 1024);
- }
- fclose($fp);
- }
- ?>
http://www.bkjia.com/PHPjc/743818.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743818.htmlTechArticleAnti-hotlink forgery referer example code, mainly used for some breakthroughs in anti-hotlinking, such as pictures, software, etc. The complete program will be given directly here. You can modify it yourself for specific applications. ...