文档引用器位置javascript远程php服务器

document referrer location javascript remote php server

本文关键字:远程 php 服务器 javascript 位置 引用 文档      更新时间:2023-09-26

我有以下代码,可以在不支持PHP的网页中以Javascript模式获取引用人,并将其传递到远程服务器:http://site.com/ref.php,其中使用$ref = $_GET['referrer'];我可以获得我想要的引用人,也可以获得位置,即在我的远程服务器中使用$loc = $_GET['location'];安装脚本的站点,所以我必须在该脚本中插入document.location,但我现在不知道如何插入。

<script>
var src = "http://site.com/ref.php"
src += "?referrer=" + escape( document.referrer );
src += "&anticache=" + new Date().getTime();
var body = document.getElementsByTagName( "body" )[0];
var image = document.createElement( "img" );
image.src = src;
body.appendChild( image );
</script>

我已尝试添加到脚本中src += "?location=" + escape( document.location );但不起作用有什么帮助吗?

src += "?location=" + escape( document.location );

如果你把它放在referreranticache参数之后,你已经得到了?;您想要的是一个&来分隔两个参数。

使用location.href优先于使用document.location,使用encodeURIComponent优先于escape

它不起作用,因为document.location是一个包含许多信息的对象:请参阅?。尝试document.location.href

代码:

var src = "http://site.com/ref.php"
src += "?referrer=" + escape( document.referrer );
src += "&anticache=" + new Date().getTime();
src += "&location=" + encodeURIComponent( location.href );