PHP,Nginx获取访问网站来源的方法

WBOY
Release: 2016-06-06 20:14:58
Original
1140 people have browsed it

想获取访问网站的来源网址,访问此网站经过了微博的短链接,还有nginx跳转,使用HTTP_REFERER是能获取一部分访问来源,但有很多的访问来源无法准确获取到,请问有什么好办法能准确获取到访问的来源?

回复内容:

想获取访问网站的来源网址,访问此网站经过了微博的短链接,还有nginx跳转,使用HTTP_REFERER是能获取一部分访问来源,但有很多的访问来源无法准确获取到,请问有什么好办法能准确获取到访问的来源?

php获取完整的来路URL

<code>$url = $_SERVER["HTTP_REFERER"]; //获取完整的来路URL

$str = str_replace("http://","",$url); //去掉http://
$strdomain = explode("/",$str); // 以“/”分开成数组
$domain = $strdomain[0]; //取第一个“/”以前的字符

用上面的方法才准确无误,如果你用PHP自带的函数就不对如:
$_SERVER['SERVER_NAME'] 这个函数它获取的是服务器域名</code>
Copy after login

Js判断搜索引擎来路的代码则如下

<code><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>
</code>
Copy after login

Nginx判断来路查询语句是否包含有Q=**,重写到https://segmentfault.com/?Q=1010000004615312

<code>if ( $query_string ~ "^Q=(.*)$" ){
    rewrite ^ "https://segmentfault.com/" last;
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template