Home >php教程 >php手册 >php HTTP_REFERER模仿代码

php HTTP_REFERER模仿代码

WBOY
WBOYOriginal
2016-05-25 16:38:52979browse

<?php  
if (!isset($_server["http_referer"]))  
echo "no referer";  
else  
echo $_server["http_referer"];

如果直接点击上面的链接,那么页面会显示referer页面的链接.代码如下:

set http = createobject("msxml2.xmlhttp")  
http.open "get","http://www.phprm.com/test/referer.php",false  
http.setrequestheader "referer","http://www.phprm.com"  
http.send  
wscript.echo http.responsetext

但是如果我用vbs调用msxml2.xmlhttp组件访问这个页面,返回的却是no referer,实在匪夷所思,难道我的代码写错了?

于是google了一下“vbs伪造http referer”,发现搜出来的内容大部分和这篇文章一样,不用看又是复制粘贴,你抄我的,我抄你的,抄来抄去不知道到底是谁的,而且还是错的!

那篇文章第一个例子是asp教程的,代码如下:

dim http  
set http=server.createobject("msxml2.xmlhttp")  
http.open "get",url,false  
http.setrequestheader "referer","http://www.fromdomain.cn/"  
http.send()

开始我还以为asp下的vbs和我直接双击运行的vbs不一样,asp下的比较牛逼,可以改referer,为此我还专门装了iis测试,发现返回的照样是no referer,后来才看到下面的留言,“原谅我对asp不熟,给不了你什么帮助,自己查点其他资料参考一下吧”,“这我没怎么玩asp了,代码只是参考来的,asp的没测试过”.

我真的不想骂人,不熟你写也就算了,起码测试一下吧,没有测试过的代码你也好意思贴上来?后来在千一网络(这个网络貌似不错)看到一个比较靠谱的答案,referer在asp和ajax中是无法通过设置header来更改的.

怒了,既然xmlhttp组件不行,我用socket来写总行了吧,注:不是所有电脑上都注册了winsock组件,代码如下:

set socket = wscript.createobject("mswinsock.winsock","winsock_")  
socket.remotehost = "www.phprm.com"  
socket.remoteport = 80  
socket.connect  
do  
wscript.sleep 100  
loop  
sub winsock_connect()  
data = "get /test/referer.php http/1.1" & vbcrlf &_  
"referer: http://www.phprm.com" & vbcrlf &_  
"host: www.phprm.com" & vbcrlf & vbcrlf  
socket.senddata data  
end sub  
sub winsock_dataarrival(bytestotal)  
socket.getdata str  
wscript.echo utf8tounicode(str)  
wscript.quit  
end sub

utf8tounicode函数比较长就不贴出来了,以前的文章写过,测试结果如下:

http/1.1 200 ok  
date: thu, 04 nov 2010 14:05:20 gmt  
server: apache  
transfer-encoding: chunked  
content-type: text/html  
f  
http://www.phprm.com  
0


本文链接:

收藏随意^^请保留教程地址.

Statement:
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