Home > Backend Development > PHP Tutorial > How to use curl to connect to the website and obtain information in PHP

How to use curl to connect to the website and obtain information in PHP

墨辰丷
Release: 2023-03-31 11:56:02
Original
1765 people have browsed it

This article mainly introduces how to use curl to open an https website in PHP. It involves the related skills of PHP using curl to connect to the website and obtain information. Friends who need it can refer to it

The example in this article tells about the use of curl in PHP How to open https website. Share it with everyone for your reference. The specific implementation method is as follows:

$url = 'https://www.google.com.hk'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11'); 
$res = curl_exec($ch); 
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
curl_close($ch) ; 
echo $res;
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

php uses the history recording function

php process control and mathematical operations Method

How to get the user IP address in PHP

The above is the detailed content of How to use curl to connect to the website and obtain information in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template