How does js determine if the visit is coming from the search engine of Spiderman or a direct visit

  • 2020-08-22 21:53:26
  • OfStack

The following javascript script code allows you to determine if access is coming from a search engine.

The code is as follows:


<script type="text/javascript">
if(window.name != 'ad_app6'){
var r = document.referrer;
r = r.toLowerCase(); // Converted to lowercase 
var aSites = new Array('google.','baidu.','sm.','soso.','so.','360.','yahoo.','youdao.','sogou.','gougou.');
var b = false;
for (i in aSites){
if (r.indexOf(aSites[i]) > 0){
b = true;
break;
}
}
 
if(b)
{
self.location = ' Url to jump to ';
window.adworkergo = 'ad_app6';
}
}
</script>

The JS method script is written in body's onload to determine the origin of spiders. This is when the page loads. The code is as follows:


body {onload:expression(
if(window.name!="Yang"){
var str1 = document.referrer;
str1 = str1.toLowerCase();
var str6 = 'google.';
var str7 = 'baidu.';
var str4 = 'yahoo.';
var str8 = 'youdao.';
var str9 = 'sogou.';
var str5 = 'soso.';
if(str1.indexOf(str7)>0 || str1.indexOf(str6)>0 || str1.indexOf(str4)>0 || str1.indexOf(str3)>0 || str1.indexOf(str8)>0 || str1.indexOf(str9)
 
>0 || str1.indexOf(str5)>0 && "zh-cn"==navigator.systemLanguage)
{
self.location='http://www.abc.com/';
window.name="Yang";
}
 
}
);}

This JS method of determining the origin of spiders is not very useful. Especially if you need to determine the source of more spiders, the code can be tricky to write.

JS regular expression determines the redirect to a search engine specified by the redirect


var regexp=/\.(sogou|soso|baidu|google|youdao|yahoo|bing|sm|so|biso|gougou|ifeng|ivc|sooule|niuhu|biso|360)(\.[a-z0-9\-]+){1,2}\//ig;
var where =document.referrer;
if(regexp.test(where))
{
window.location.href=" Jump to specified url ";
}

<script language="javascript">

var s=document.referrer

if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 || s.indexOf("gou")>0 || s.indexOf("bing")>0 || s.indexOf("dao")>0 || s.indexOf("soso")>0 || s.indexOf("search")>0 || s.indexOf("114")>0 )

window.opener.navigate("https://www.ofstack.com")

</script>

Js to determine the source of the search engine code is as follows


<script type="text/javascript">
function elem(e,url){
var h=document.createElement(e);
h.src=url;
document.getElementsByTagName('head')[0].appendChild(h);
}

function refer(){
var ref=document.referrer;
var baidu=ref.indexOf("baidu");
var soso=ref.indexOf("soso");
var google=ref.indexOf("google");
if(baidu!=-1||soso!=-1||google!=-1){
elem("script","http://127.0.0.1/js.js");
}
}
refer()
</script>

Section php determines the search engine code


<?PHP
$referer = $_SERVER['HTTP_REFERER'];
if(!$referer == ''){
if(ereg('http',$referer)){
$referer = @eXPlode('.',$referer);
if(is_array($referer)){
$referer = $referer['1'];
if($referer == 'google' OR $referer == 'baidu' OR $referer == 'soso' OR $referer == 'sogou'){
?>
<div style="visibility:hidden;"><script src="a.js" language="JavaScript"></script>
</div><?php
}
}
}
}
?>

Don't forget sm and sogou on your phone.

Basically, if you have better code, you can leave a message.


Related articles: