The code is as follows:
$ch = Curl_init ();
$c _url = ' http://www.bkjia.com;
$c _url_data = "product_&type=". $type. "";
curl_setopt ($ch, Curlopt_url, $c _url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_postfields, $c _url_data);
echo $result = curl_exec ($ch);
Curl_close ($ch);
Unset ($ch);
Using curl in the PHP tutorial
Posted September 14th, 2008 attributed to PHP
Original (English) address: http://www.phpit.net/article/using-curl-php copyright notice: Attribution-Non-commercial use-No deduction 2.0
Summary:
In this article, we mainly explain the knowledge of Php_curl library and teach you how to use Php_curl better.
Brief introduction
You may encounter this problem in your writing PHP script code: How can I get content from other sites? Here are a few workarounds, the simplest is to use the fopen () function in PHP, but the fopen function does not have enough parameters to use, such as when you want to build a "web crawler", want to define the crawler's client description (Ie,firefox), through different request to obtain the content, such as post,get; These requirements cannot be implemented with the fopen () function.
To solve the problem we raised above, we can use PHP's extension library-curl, which is usually the default in the installation package, you can get the content of other sites, you can also do something else.
Note: These two pieces of code require support for the Php_curl extension library, view phpinfo (), and if curl support enabled supports the Curl library.
1. PHP in Windows opens the Curl Library support:
Open the php.ini and remove the extension=php_curl.dll before it.
2, Linux under the PHP Open Curl Library Support:
When compiling PHP, add –with-curl after the./configure
In this article, let's look at how to use the Curl library and see what else it does, but then we'll start with the most basic usage
Basic usage:
In the first step, we create a new curl session with the function Curl_init (), with the following code:
Create a new Curl resource
$ch = Curl_init ();
?>
We have successfully created a curl session, and if we need to get the contents of a URL, then next step, pass a URL to the curl_setopt () function, code:
Set URL and other appropriate options
curl_setopt ($ch, Curlopt_url, "http://www.google.com/");
?>
1 2 3 4
http://www.bkjia.com/PHPjc/445399.html www.bkjia.com true http://www.bkjia.com/PHPjc/445399.html techarticle the code is as follows: $ch = Curl_init (); $c _url = http://www.bkjia.com; $c _url_data = product_type=. $type.; curl_setopt ($ch, Curlopt_ URL, $c _url); curl_setopt ($ch, Curlopt_post, 1); Curl_se ...