Perfectly compatible with major browsers to get an HTTP_REFERER method summary

  • 2020-03-30 03:26:20
  • OfStack

The HTTP_REFERER submission that IE can recognize is either an event triggered by a click or a request to submit a Form Form. Here is a summary of the method based on the online literature:


<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= " //www.jb51.net " ;
referURL(url);
</script>

This method first USES document.all to determine whether the current browser is IE, then generates a link if it is, then automatically executes the onclick event, if not, then USES JS to jump. This gives you HTTP_REFERER on the page you're working on

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

2. PHP USES curl to forge an IP and an incoming 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')); //To construct the IP
curl_setopt($ch, CURLOPT_REFERER, "//www.jb51.net/ ");  // Tectonic background 
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"];


Related articles: