This article analyzes the usage of http_referer function in PHP. Share to everyone for your reference. The specific analysis is as follows:
The use of PHP's Http_referer function to determine the user's antecedents, this is relatively simple, the example code is as follows:
Copy Code code as follows:
<?php
if (Isset ($_server[' http_referer ')) {
Print "The page you were on previously is {$_server[' http_referer ']}<br/>";
} else {
Print "You didn ' t click any links to get here<br/>";
}
?>
<a href= "refer.php" >click me!</a>
Here's what we let the user not know about our routing, the example code is as follows:
Copy Code code as follows:
<?php
$host = "Www.jb51.net";
$referer = "http://". $host;
$fp = Fsockopen ($host, $errno, $errstr, 30);
if (! $fp) {
echo "$errstr ($errno) <br>;n";
}else{
$request = "
get/http/1.1
Accept:image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, Application/x-shockwave-flash, application/ Vnd.ms-powerpoint, Application/vnd.ms-excel, Application/msword, * * "." *
referer:http://$host
Accept-language:zh-cn
Accept-encoding:gzip, deflate
user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection:close "
." Rnrn ";
Fputs ($fp, "$request");
while (!feof ($FP))
{
$res [] = fgets ($fp, 1024);
}
$html = Join ("", $res);
Fclose ($FP);
$fp = file_put_contents ("123cha.html", $html);
echo "Done";
}
That's all you got?
However, it is very strange that Www.jb51.net's page is garbled (except for HTTP headers), which is why? Is it because of the use of gzip compression?
Copy Code code as follows:
<?php
$host = "Www.jb51.net";
$html = file_get_contents ("http://". $host);
$fp = file_put_contents ("hao123.html", $html);
echo "Done";
?>;
But this is not a problem to grasp, and then to analyze the beginning of the grasp of the HTTP header:
http/1.1 OK date:wed Aug 00:59:36 GMT server:apache/1.3.27 cache-control:max-age=1296000 Expires:thu, 15 Sep 00:59:36 GMT Last-modified:mon Aug-13:56:00 GMT accept-ranges:bytes connection:close content-type:te xt/html Content-encoding:gzip content-length:14567
Sure enough, content-encoding:gzip, originally compressed, the length of 14567 bytes, with the second method of grasping, the original uncompressed HTML is 71143 bytes, the original file_get_contents can also be automated decompression.
PHP instance two, the code is as follows:
Copy Code code as follows:
<?php
$host = ' 127.0.0.1 ';
$target = '/2.php ';
$referer = ' http://www.jb51.net '; Forged Http_referer Address
$fp = Fsockopen ($host, $errno, $errstr, 30);
if (! $fp) {
echo "$errstr ($errno) <br/>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);
}
?>
Another 2.php file is simple, just write a line to read the current Http_referer server value of the code can be as follows:
Copy Code code as follows:
<?php
echo "echo $_server["Http_referer"];
?>
I hope this article will help you with your PHP program design.