Perfect compatibility with various browsers to get the HTTP_REFERER method summary

Source: Internet
Author: User

Later, I checked some relevant information and found that the window is used in IE. location. href or HTTP_REFERER cannot be obtained. It is really a browser that doesn't understand IE. Many browsers run very well, but it doesn't support it. There is no way at last, PHP can only forge the HTTP_REFERER method or use JS to forge the source.

The HTTP_REFERER submission that can be recognized by IE is a click-triggered event or a Form-submitted request. The following is a summary of the online materials:

<script>function referURL(url){var isIe=(document.all)?true:false;if(isIe) {var linka = document.createElement(‘a');linka.href=url;document.body.appendChild(linka);linka.click();}else window.location = url;}var url=”http://www.jb51.net”;referURL(url);</script>

This method first uses document. all to determine whether the current browser is IE. If yes, a link is generated and The onclick event is automatically executed. If not, JS jump is used. In this way, you can get HTTP_REFERER on the processing page.

This method is tested in IE, Firefox, Safari, and Chrome

2. PHP uses curl to forge IP addresses and generate HTTP Referrer

Referer. php

<? Php $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, "http://mydomain.com/ip.php"); curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('x-FORWARDED-FOR: 8.8.8.8.8 ', 'client-IP: 8.8.8.8 '); // construct IPcurl_setopt ($ ch, CURLOPT_REFERER, "http://www.jb51.net/"); // construct the origin curl_setopt ($ ch, CURLOPT_HEADER, 1 ); $ out = curl_exec ($ ch); curl_close ($ ch); echo $ out;

Ip. php

<?phpfunction getClientIp() {if (!empty($_SERVER["HTTP_CLIENT_IP"]))$ip = $_SERVER["HTTP_CLIENT_IP"];else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];else if (!empty($_SERVER["REMOTE_ADDR"]))$ip = $_SERVER["REMOTE_ADDR"];else$ip = "err";return $ip;}echo "IP: " . getClientIp() . "<br>";echo "referer: " . $_SERVER["HTTP_REFERER"];

Related Article

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.