php中XMLHttpRequest(Ajax)不能设置自定义的Referer的解决方法
更新时间:2011年11月26日 23:36:22 作者:
php中XMLHttpRequest(Ajax)不能设置自定义的Referer的解决方法,需要的朋友可以参考下。
解决方法: 使用服务器作为代理.
在PHP中, 使用我最喜欢的最强大的CURL,嘿嘿
下面是在万网查询域名的实例代码
<?php
$dn = $_GET['dn']; // 域名, 不包括www
$ex = $_GET['ex']; // 顶级域名, 如 .com, .cn, 包括最前面的.
// 查询域名是否已经注册
$url = 'http://pandavip.www.net.cn/check/check_ac1.cgi';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, 'domain='.$dn.$ex);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0');
curl_setopt($ch, CURLOPT_COOKIE, '__utma=1.1486902564.1322109246.1322109246.1322109246.1; __utmz=1.1322109246.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AdSource=GOOGLE%u641C%u7D22; AdWordID=gg96011009070005; __utmc=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
'Referer' => 'http://pandavip.www.net.cn/cgi-bin/Check.cgi?queryType=0&domain1='.$dn.'&image.x=0&image.y=0&domain='.$dn.'&big5=n&sign=2&url=www.net.cn&'.trim($ex, '.').'=yes' // 冒名顶替, 嘿嘿
));
curl_exec($ch); // 将查询结果返回前端, 用JS处理
在PHP中, 使用我最喜欢的最强大的CURL,嘿嘿
下面是在万网查询域名的实例代码
复制代码 代码如下:
<?php
$dn = $_GET['dn']; // 域名, 不包括www
$ex = $_GET['ex']; // 顶级域名, 如 .com, .cn, 包括最前面的.
// 查询域名是否已经注册
$url = 'http://pandavip.www.net.cn/check/check_ac1.cgi';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, 'domain='.$dn.$ex);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0');
curl_setopt($ch, CURLOPT_COOKIE, '__utma=1.1486902564.1322109246.1322109246.1322109246.1; __utmz=1.1322109246.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AdSource=GOOGLE%u641C%u7D22; AdWordID=gg96011009070005; __utmc=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
'Referer' => 'http://pandavip.www.net.cn/cgi-bin/Check.cgi?queryType=0&domain1='.$dn.'&image.x=0&image.y=0&domain='.$dn.'&big5=n&sign=2&url=www.net.cn&'.trim($ex, '.').'=yes' // 冒名顶替, 嘿嘿
));
curl_exec($ch); // 将查询结果返回前端, 用JS处理
相关文章
PHP使用内置函数file_put_contents写入文件及追加内容的方法
这篇文章主要介绍了PHP使用内置函数file_put_contents写入文件及追加内容的方法,结合实例形式分析了file_put_contents函数通过参数设置实现写入文件及追加内容的相关技巧,非常简单实用,需要的朋友可以参考下2015-12-12
解决了Ajax、MySQL 和 Zend Framework 的乱码问题
功夫不负有心人,花了将近一天时间,终于解决了Ajax 、MySQL 和 Zend Framework 的乱码问题。现在总结如下,以供参考。2009-03-03


最新评论