11.5. Fetching an HTTPS URL
Problem
You want to retrieve a secure URL.
Solution
Use the cURL extension with an HTTPS URL:
$c = curl_init('https://secure.example.com/accountbalance.php'); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec($c); curl_close($c);
Discussion
To retrieve secure URLs, the cURL extension needs access to an SSL library, such as OpenSSL. This library must be available when PHP and the cURL extension are built. Aside from this additional library requirement, cURL treats secure URLs just like regular ones. You can provide the same cURL options to secure requests, such as changing the request method or adding POST data.
See Also
The OpenSSL Project at http://www.openssl.org/.
Get PHP Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.