Php HTTP_REFERER function usage

Source: Internet
Author: User

 

Using the http_referer function in the php tutorial to determine the user's path is simple,
Instance

If (isset ($ _ SERVER ['HTTP _ referer']) {
Print "The page you were on previusly was {$ _ SERVER ['HTTP _ referer']}
";
} Else {
Print "You didn't click any links to get here
";
}
?>

Click me!

Next, let the user not know how to handle it.
Instance

] $ Host = "www.123cha.com ";
$ Referer = "http: //". $ host;
$ Fp = fsockopen ($ host, 80, $ 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 ";
} [/Code]

That's not enough?

But the strange thing is,
Www.hao123.com
The page is garbled (except the http header). Why? Is it because gzip is used for compression?

[Code] $ Host = "www.zhutiai.com ";
$ Html = file_get_contents ("http: //". $ host );
$ Fp = file_put_contents ("hao123.html", $ html );
Echo "done ";
?>; [/Code]


But there is no problem with this.

Analyze the http Header
[Code] HTTP/1.1 200 OK Date: Wed, 31 Aug 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, 29 Aug 2005 13:56:00 GMT Accept-Ranges: bytes Connection: close Content-Type: text/html Content-Encoding: gzip Content-Length: 14567 [/code]

Sure enough, Content-Encoding: gzip
Originally compressed, with a length of 14567 bytes,
The second method is used to capture. The original uncompressed html is 71143 bytes. The original file_get_contents can also be automatically decompressed.


Instance 2

$ Host = '1970. 0.0.1 ';
$ Target = '/2. php ';
$ Referer = 'HTTP: // www.bkjia.com '; // forged HTTP_REFERER address
$ 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 );
}
?>

Another 2. php file is very simple. Just write a line of code to read the current HTTP_REFERER server value, as shown below:

Echo"

";
Echo $ _ SERVER ["HTTP_REFERER"];
?>

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.