Details on using curl in php _ PHP Tutorial

Source: Internet
Author: User
Detailed instructions on using curl in php. The curl in php is a file I mentioned earlier. I will share with you my experiences on using phpcurl. I hope this will be helpful to you. I have mentioned this file before curl in php, which I have worked on in the past two days. next I will share with you my experiences in using php curl, I hope this will help you.

Curl is used for the work done in the past two days.

When the requested url is not on the same server, you cannot directly access it.

In this case, it is best to use curl. it is simple and convenient to simulate post requests.

Below is a record of the accumulation in the use process

The code is as follows:

/*
Remote post request
*/
Function getRemoteUrl ($ get_url ){
$ Curl = curl_init (); # Start a CURL session
Curl_setopt ($ curl, CURLOPT_URL, $ get_url); # set a Url
Curl_setopt ($ curl, CURLOPT_POST, true); # send a regular Post request
Curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); # set the timeout limit to prevent endless loops
Curl_setopt ($ curl, CURLOPT_HEADER, 0); # display the returned Header area content
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); # The obtained information is returned as a file stream
$ Return = curl_exec ($ curl); # perform the operation
If (curl_errno ($ curl )){
Return false;
}
Curl_close ($ curl); # Close a CURL session
Return $ return;
}

Function getCurlData ($ url ){
$ Curl = curl_init ();
Curl_setopt ($ curl, CURLOPT_URL, $ url );
Curl_setopt ($ curl, CURLOPT_HEADER, false );
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ curl, CURLOPT_TIMEOUT, 10 );
$ Result = curl_exec ($ curl );
Curl_close ($ curl );
Return $ result;
}

To sum up the curl method:

Initialize curl first
Use curl_setopt to set the target url and other options
Curl_exec: execute curl
Disable curl
The last step is output.

Curl () is highly efficient and supports multiple threads. However, you need to enable curl extension. The steps to enable curl extension are as follows:

1. copy the three php_curl.dll, libeay32.dll, and ssleay32.dll files in the PHP folder to system32;

2. remove the semicolon from php. ini (c: WINDOWS directory) and extension = php_curl.dll;

3. restart apache or IIS

I hope this will be helpful to you. Work done in the past two days...

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.