Use curl_init function (1/4) in PHP)

Source: Internet
Author: User

 

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 );

Use curl in php tutorial
Posted September 14 th, 2008 belongs to php
Address: http://www.phpit.net/article/using-curl-php copyright statement: Signature-non-commercial use-deduction prohibited 2.0
Abstract:
This article describes the php_curl library and how to better use php_curl.
Introduction
You may encounter the following problem in your php script code: How can I get content from other sites? Here are several solutions. The simplest thing is to use the fopen () function in php, but the fopen function does not have enough parameters to use. For example, if you want to build a "web crawler ", to define the crawler client description (ie, firefox), you can obtain the content through different request methods, such as post and get. These requirements cannot be implemented using the fopen () function.
To solve the problem we raised above, we can use the php extension library-curl. This extension library is usually in the installation package by default, and you can obtain the content of other sites, you can also do something else.
Note: The two codes must be supported by the php_curl extension library. View phpinfo (). If curl support is enabled, the curl library is supported.
1. Enable curl library support for php in windows:
Open php. ini and remove the; sign before extension = php_curl.dll.
2. Enable curl library support for php in linux:
Add-with-curl after./configure during php Compilation
In this article, let's take a look at how to use the curl library and its other functions. However, next we will start with the most basic usage.
Basic usage:
Step 1: Use the curl_init () function to create a new curl session. The Code is as follows:
// Create a new curl resource
$ Ch = curl_init ();
?>
We have successfully created a curl session. If you need to obtain the content of a url, pass a url to the curl_setopt () function in the next step. The Code is as follows:
// Set url and other appropriate options
Curl_setopt ($ ch, curlopt_url, "http://www.google.com /");
?>

1 2 3 4

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.