Home  >  Article  >  Backend Development  >  How to use php curl_init function

How to use php curl_init function

藏色散人
藏色散人Original
2019-05-27 10:31:113475browse

php The curl_init function initializes a cURL session, that is, initializes a new session and returns a cURL handle for use by the curl_setopt(), curl_exec() and curl_close() functions.

How to use php curl_init function

php How to use the curl_init function?

curl_init — Initialize a cURL session

Description

resource curl_init ([ string $url = NULL ] )

Initialize a new session and return a cURL handle for curl_setopt(), curl_exec() and curl_close () function usage.

Parameter url, if this parameter is provided, the CURLOPT_URL option will be set to this value. You can also set this value manually using the curl_setopt() function.

Return value

If successful, return a cURL handle, return FALSE on error.

Example

Initialize a new cURL session and get a web page

<?php
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, "http://www.php.cn/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// 抓取URL并把它传递给浏览器
curl_exec($ch);

// 关闭cURL资源,并且释放系统资源
curl_close($ch);
?>

The above is the detailed content of How to use php curl_init function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn