Home > Backend Development > PHP Tutorial > Three ways to forge the URL source of the HTTP_REFERER page in php

Three ways to forge the URL source of the HTTP_REFERER page in php

高洛峰
Release: 2023-03-04 15:22:01
Original
2244 people have browsed it

php gets the URL address of the previous page of the current page, that is, which page the current page is linked from. You can use $_SERVER['HTTP_REFERER'], but the URL address of this source page can be forged and spoofed. This article introduces three methods of forging HTTP_REFERER page URLs. Friends in need can refer to them.

$_SERVER['HTTP_REFERER'] is a super variable used by PHP to determine the parent source page of the page. We can use $_SERVER['HTTP_REFERER'] to determine which page we entered from. This page has been added so we can track it better.

But $_SERVER['HTTP_REFERER'] can also be forged and deceived. 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);
Copy after login

stream_context_create in file_get_contents forges important parameters of the source.

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); 
curl_close ($ch);
Copy after login

The parameter http://www.manongjc.com is the forged URL address.

The third method: 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); 
}
Copy after login

Among the above three methods, the third method fsockopen has the best performance and effect, so it is recommended that you use the third method.

The above is the collection of information on the source of the URL of the PHP forged HTTP_REFERER page. We will continue to add relevant information in the future. Thank you for your support of this site!

For more php three methods of forging the URL source of the HTTP_REFERER page, please pay attention to the PHP Chinese website for related articles!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template