Example of http_referer function usage in PHP, phphttp_referer
This paper analyzes the usage of http_referer function in PHP. Share to everyone for your reference. The specific analysis is as follows:
Using PHP's Http_referer function to determine the user's antecedents, this is relatively simple, the example code is as follows:
Copy CodeThe code is as follows: <?php
if (Isset ($_server[' http_referer ')) {
Print "The page were on previously is {$_server[' http_referer ']}
";
} else {
print "didn" t click any links to get here
";
}
?>
Click me!
Here is what we let the user do not know our antecedents, the example code is as follows:
Copy CodeThe code is as follows: <?php
$host = "Www.jb51.net";
$referer = "http://". $host;
$fp = Fsockopen ($host, $errno, $errstr, 30);
if (! $fp) {
echo "$errstr ($errno)
; 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";
}
Is that all right?
But oddly enough, Www.jb51.net's page was garbled (except for HTTP headers), which is why? Is it because of the use of gzip compression?
Copy the 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 that's fine, then analyze the HTTP header that starts to catch:
http/1.1 OK date:wed, 2005 00:59:36 GMT server:apache/1.3.27 cache-control:max-age=1296000 Expires:thu, 15 SEP 2005 00:59:36 GMT Last-modified:mon, 2005 13:56:00 GMT Accept-ranges:bytes connection:close content-type:te xt/html Content-encoding:gzip content-length:14567
Indeed there is this sentence, Content-encoding:gzip, the original 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 automatically decompressed.
PHP example Two, the code is as follows:
Copy the Code code as follows: <?php
$host = ' 127.0.0.1 ';
$target = '/2.php ';
$referer = ' http://www.bkjia.com '; Forged Http_referer Address
$fp = Fsockopen ($host, $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);
}
?>
Another 2.php file is simple, just write a line to read the current Http_referer server value code, as follows:
Copy the Code code as follows: <?php
echo "
";
echo $_server["Http_referer"];
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/915427.html www.bkjia.com true http://www.bkjia.com/PHPjc/915427.html techarticle PHP http_referer Function Usage example, phphttp_referer This article to analyze the Http_referer function usage in PHP. Share to everyone for your reference. The specific analysis is as follows: Using PHP http ...