Home > Article > Web Front-end > Perfectly compatible with major browsers to obtain HTTP_REFERER method summary_javascript skills
Later I checked some relevant information and found that IE cannot get HTTP_REFERER through window.location.href or I really don’t understand IE’s browser. Many browsers run very good things, but it just doesn’t support it. , in the end there is no way but to forge the source HTTP_REFERER method in PHP or use JS to forge it.
The HTTP_REFERER submission that IE can recognize is an event triggered by a click or a request submitted by a Form form. The following is a method summarized based on online information:
<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 so, it generates a link, and then automatically executes the onclick event. If not, it uses JS to jump. In this way, you can get HTTP_REFERER when processing the page
This method has been tested in IE, Firefox, Safari and Chrome
2. PHP uses curl to forge IP and source 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', 'CLIENT-IP:8.8.8.8')); //构造IP curl_setopt($ch, CURLOPT_REFERER, "http://www.jb51.net/ "); //构造来路 curl_setopt($ch, CURLOPT_HEADER, 1); $out = curl_exec($ch); curl_close($ch); echo $out;
ip.php
<?php function 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"];