In php, XMLHttpRequest (Ajax) cannot set a custom Referer solution.

Source: Internet
Author: User
In php, XMLHttpRequest (Ajax) cannot set a custom Referer solution. For more information, see. Solution: Use the server as the proxy.
In PHP, use my favorite most powerful CURL.
The following is the instance code for querying Domain names on www.net.cn.

The code is as follows:


$ Dn = $ _ GET ['dn ']; // domain name, excluding www
$ Ex = $ _ GET ['x']; // top-level domain names, such as. com and. cn, including the top-level domain names.
// Query whether the domain name has been registered
$ 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 = encrypt; _ utmz = 1.132220.246.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 it to 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' // impersonate, hey
));
Curl_exec ($ ch); // returns the query result to the front end, which is processed by JS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.