Skip to Content
PHP Cookbook
book

PHP Cookbook

by David Sklar, Adam Trachtenberg
November 2002
Intermediate to advanced
640 pages
16h 33m
English
O'Reilly Media, Inc.
Content preview from PHP Cookbook

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/.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
PHP Cookbook, 2nd Edition

PHP Cookbook, 2nd Edition

Adam Trachtenberg, David Sklar
PHP Cookbook, 3rd Edition

PHP Cookbook, 3rd Edition

David Sklar, Adam Trachtenberg
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe

Publisher Resources

ISBN: 1565926811Supplemental ContentCatalog PageErrata