php curl Obtains the content of https page and does not directly output the setting method of returning results
- 2021-11-13 01:07:52
- OfStack
Using php curl to get page content or submit data, you sometimes want the returned content to be stored as a variable rather than output directly.
Method: Set the CURLOPT_RETURNTRANSFER option for curl to 1 or true.
eg:
$url = 'http://www.baidu.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// Don't http header Accelerate efficiency
curl_setopt($curl, CURLOPT_HEADER, 0);
// https Request Do not verify certificates and hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch); // Content has been obtained , Not output to page .
curl_close($ch);