document.referrer 取当前页面的上一页来源,当然这个是可以伪造的。
request.getHeader("referer");
如果有兴趣可以看看:如何改变或伪造HTTP-REFERER
http://www.aslibra.com/blog/read.php?860
原理都是sock构造http头来senddata。其他语言什么的比如perl也可以,目前比较简单的防御伪造referer的方法是用验证码(Session)。现在有一些能防盗链软件的商业公司比如UUDOG,linkgate,VirtualWall什么的,都是开发的应用于IIS上面的 dll。有的是采用cookies验证、线程控制,有的是能随机生成文件名然后做URL重写。有的方法能的确达到不错的效果.
内容:
原理都是sock构造http头来senddata。其他语言什么的比如perl也可以,目前比较简单的防御伪造referer的方法是用验证码(Session)。
dim http
set http=server.createobject("MSXML2.XMLHTTP") '//MSXML2.serverXMLHTTP也可以
Http.open "GET",url,false
Http.setRequestHeader "Referer","http://www.fromdomain.cn/"
Http.send()
set http=server.createobject("MSXML2.XMLHTTP") '//MSXML2.serverXMLHTTP也可以
Http.open "GET",url,false
Http.setRequestHeader "Referer","http://www.fromdomain.cn/"
Http.send()
PHP(前提是装了curl):
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.readdomain.cn/xxx.asp");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.fromdomain.cn/");
curl_exec ($ch);
curl_close ($ch);
curl_setopt ($ch, CURLOPT_URL, "http://www.readdomain.cn/xxx.asp");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.fromdomain.cn/");
curl_exec ($ch);
curl_close ($ch);
PHP(不装curl用sock)
$server = 'www.readdomain.cn';
$host = 'www.fromdomain.cn';
$target = '/xxx.php';
$referer = 'http://www.aslibra.com/'; // Referer
$port = 80;
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "GET $target HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Cookie: SESSIONID=test\r\n";
$out .= "Referer: $referer\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
$host = 'www.fromdomain.cn';
$target = '/xxx.php';
$referer = 'http://www.aslibra.com/'; // Referer
$port = 80;
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "GET $target HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Cookie: SESSIONID=test\r\n";
$out .= "Referer: $referer\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
VB.NET/C#.NET
Dim oXMLHttp As MSXML2.XMLHTTP30 = New MSXML2.XMLHTTP30()
或者
MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30();
oXMLHttp.open(....
oXMLHttp.setRequestHeader(...
oXMLHttp.send(..
或者
MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30();
oXMLHttp.open(....
oXMLHttp.setRequestHeader(...
oXMLHttp.send(..