Three methods for php to forge HTTP_REFERER page URL Source: http_refererurl
Php obtains the URL of the previous page from which the current page is linked. You can use $ _ SERVER ['HTTP _ referer']. however, the URL address of the source page can be forged or spoofed. This article introduces three methods for forging HTTP_REFERER page URL. 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!