Three methods for php to forge HTTP_REFERER page URL sources

Source: Internet
Author: User
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!

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.