PHP uses CURL to get the address instance after 302 jump _ PHP Tutorial

Source: Internet
Author: User
PHP uses CURL to obtain the address instance after the 302 jump. Directly run the code: Copy the code as follows: * return a 302 address * functioncurl_post_302 ($ url, $ vars) {$ chcurl_init (); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_s directly uploads the code:

The code is as follows:


/* Return a 302 address */
Function curl_post_302 ($ url, $ vars ){

$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // 302 redirect
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ vars );
$ Data = curl_exec ($ ch );
$ Headers = curl_getinfo ($ ch );
Curl_close ($ ch );
If ($ data! = $ Headers)
Return $ Headers ["url"];
Else
Return false;

}

The above curl_post_302 function can directly get the jump address of 302.

The response code is as follows:/* returns a 302 address */function curl_post_302 ($ url, $ vars) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_s...

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.