This article mainly introduces three methods for php to forge HTTP_REFERER page URL sources. For more information, see php to obtain the URL of the previous page, that is, from which the current page is linked, you can use $ _ SERVER ['http _ referer'], but the URL address of the source page can be forged and spoofed, this article introduces three methods to forge HTTP_REFERER page URLs. For more information, see.
$ _ SERVER ['http _ referer'] is a super variable used by php to determine the source page of a page, we can use $ _ SERVER ['http _ referer'] to determine from which page to enter, so that we can perform better tracking.
However, $ _ SERVER ['http _ referer'] can also be spoofed and spoofed. There are three methods to forge and fool $ _ SERVER ['http _ referer']
Method 1: 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 spoofs important parameters of the source.
Method 2: 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); curl_close ($ch);
A parameter http://www.manongjc.com is a forged URL address.
Method 3: fsockopen
$server = 'www.manongjc.com'; $host = 'www.manongjc.com'; $target = 'index.php'; $referer = 'http://www.manongjc.com/'; // Referer $port = 80; $fp = fsockopen($server, $port, $errno, $errstr, 30); 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); }
Among the above three methods, the third method fsockopen has the best performance and effect, so we recommend that you use the third method.
The above is to sort out the URL source information for the PHP forged HTTP_REFERER page. we will continue to add relevant information in the future. thank you for your support for this site!
For more information about three methods for php to forge HTTP_REFERER page URL sources, refer to the PHP Chinese website!