Home > Backend Development > PHP Tutorial > How to solve the problem that XMLHttpRequest (Ajax) cannot set a custom Referer_PHP tutorial

How to solve the problem that XMLHttpRequest (Ajax) cannot set a custom Referer_PHP tutorial

WBOY
Release: 2016-07-13 16:55:31
Original
1151 people have browsed it

This article introduces the solution to the problem that XMLHttpRequest (Ajax) cannot set a custom Referer. We mainly use the server as a proxy. It is a curl-based method.

In PHP, use my favorite and most powerful CURL, hehe

The following is an example code for querying domain names on Wanwang

$dn = $_GET['dn']; // Domain name, excluding www
$ex = $_GET['ex']; // Top-level domain name, such as .com, .cn, including the first .
// Check whether the domain name has been registered

The code is as follows
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
代码如下 复制代码


$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处理

Copy code
$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_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', // Set to Ajax mode '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' // Impostor, hehe )); curl_exec($ch); // Return the query results to the front end and process them with JS
http://www.bkjia.com/PHPjc/631673.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631673.htmlTechArticleThis article introduces the solution to the problem that XMLHttpRequest (Ajax) cannot set a custom Referer. We mainly use the server as Agent. To handle, it is based on the curl method. In PHP...