PHP forged http_referer page URL source of three ways _php instance

Source: Internet
Author: User

PHP get the current page of the previous page URL address, that is, the current page from which page chain received, you can use $_server[' http_referer '], but this source page URL address can be forged and deceived, this article to introduce the forgery of HTTP_ Referer page URL of the three ways, the need for friends can refer to.

$_server[' Http_referer ' is a super variable that PHP uses to determine the page's superior source, and we can use $_server[' http_referer ' to determine from which page we are entering this page, So we can do a better job of tracking.

But $_server[' http_referer ' can also be forged and deceived, and there are three ways to forge and deceive $_server[' http_referer '

The first method: File_get_contents

$opt =array (' http ' =>array (' header ' => ' Referer: $refer ')); 
$context =stream_context_create ($opt); 
$file _contents = file_get_contents ($url, False, $context);

In file_get_contents, stream_context_create the important parameters for forging the source.

The second method: CURL

$ch = Curl_init (); 
curl_setopt ($ch, Curlopt_url, "http://www.manongjc.com"); 
curl_setopt ($ch, Curlopt_referer, "http://www.manongjc.com"); 
Curl_exec ($ch); 

Parameter http://www.manongjc.com is a spoofed URL address.

The third method: Fsockopen

$server = ' www.manongjc.com '; 
$host = ' www.manongjc.com '; 
$target = ' index.php '; 
$referer = ' http://www.manongjc.com/'; Referer 
$port =; 
$fp = Fsockopen ($server, $port, $errno, $errstr,); 
if (! $fp) { 
 echo $errstr ($errno) \ n "; 
} else{ 
$out = "Get $target http/1.1\r\n"; 
$out. = "Host: $host \ r \ n"; 
$out. = "Referer: $referer \ r \ n"; 
$out. = "connection:close\r\n\r\n"; 
Fwrite ($fp, $out); 
while (!feof ($fp)) { 
echo fgets ($FP, 128); 
} 
Fclose ($FP); 
 
 

Of the top three methods, the third method is best fsockopen performance and effectiveness, so it is recommended that you use a third method.

Above is the PHP forged http_referer page URL source data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.