Home > Backend Development > PHP Problem > How to set a fake referer address in PHP

How to set a fake referer address in PHP

藏色散人
Release: 2023-03-04 12:06:01
Original
3686 people have browsed it

How to set the referer address in php: 1. Forge the referer address through CURL; 2. Set the referer address using SOCKET; 3. Use the "file_get_contents" method to forge and set the referer address.

How to set a fake referer address in PHP

Recommended: "PHP Video Tutorial"

Use PHP to forge the referer address

Many times we use the referer address. By judging where the previous page came from, we can learn a lot of information, but now the referer is not that reliable data because we can forge the referer address. Here we introduce the implementation methods of CURL, SOCKET, and file_get_contents respectively. The detailed codes are as follows:

CURL method

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.hujuntao.com");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.hujuntao.com/");
curl_exec ($ch);
curl_close ($ch);
Copy after login

SOCKET method

$server = ‘www.hujuntao.com’;
$host = ‘www.hujuntao.com’;
$target = ‘index.php’;
$referer = ‘http://www.hujuntao.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

file_get_contents method

$opt=array(‘http’=>array(‘header’=>"Referer: $refer"));
$context=stream_context_create($opt);
$file_contents = file_get_contents($url,false, $context);
Copy after login

Through the above In the code, we disguise the referer address as http://www.hujuntao.com. You can write a piece of code:

$_SERVER['HTTP_REFERER'];
Copy after login

to view this referer address. It’s that simple, so the referer is not reliable. Data.

The above is the detailed content of How to set a fake referer address in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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