May 10

Today i found this very cool tutorial regarding the using of using ssl with PHP.

I’ll copy here the most interesting of it.

HTTP with PHP Sockets

// don’t need to specify http, it’s the default protocol
$hostname = “www.google.com”;
$port = 80;

// create and configure the client socket
$fp = fsockopen($hostname, $port); // optional: $error_number, $error_string, $connect_timeout
if ($fp) {
stream_set_timeout($fp, 30); // seconds to wait for i/o operations

// send request headers
fwrite($fp, “GET / HTTP/1.1\r\n”);
fwrite($fp, “Host: $hostname\r\n”);
fwrite($fp, $additional_headers); // Accept, User-Agent, Referer, etc.
fwrite($fp, “Connection: close\r\n”);

// read response
$response = “”;
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
echo $response;

// close the socket
fclose($fp);
}

Direct SSL Sockets in PHP

You don’t have to send request headers in the above example. You can actually connect to some servers and send raw text with fwrite. Because you have to implement the HTTP/HTTPS protocol yourself if you want it, sockets are considered “clean” connections.
You don’t have to send request headers in the above example. You can actually connect to some servers and send raw text with fwrite. Because you have to implement the HTTP/HTTPS protocol yourself if you want it, sockets are considered “clean” connections.

// note that “ssl” is the protocol, NOT “https”
$hostname = “ssl://your-secure-site.com”;
$port = 443;

// create and configure the client socket
$fp = fsockopen($hostname, $port);
if ($fp) {
stream_set_timeout($fp, 30);

// send data (or build HTTPS headers similar to first example)
fwrite($fp, “your message goes here”);

// read response
while (!feof($fp)) {
echo fgets($fp, 128);
}

// close the socket
fclose($fp);
}

HTTPS via cURL

PHP doesn’t directly support attaching client certificates to web requests with fsockopen, so you have to use the cURL library.
$url = “https://your-secure-site.com/secure-service.php”;
$port = 443;

// POST data, formatted just like a GET query string
$request = “name=hb&age=27&site=arguments.callee.info”;

// the client certificate path MUST be a physical path, not url
$certificate = “C:\\certificates\\test.crt”; // windows example
$certificate = “/etc/pki/tls/private/test.crt”; // unix/linux example
$password = ‘mypassword’; // client certificate’s key

// more details at http://php.net/curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $certificate);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $password);

// fetch response and close the socket
$response = curl_exec($ch);
curl_close($ch);

4 Responses to “HTTP, HTTPS, and SSL via PHP”

  1. HB Says:

    Cool, glad you found the tutorial interesting. I actually used that second method last year in ATM software, so these are definitely real-world examples. Thanks for the visit!

  2. Georgi Mitev Says:

    Thank you HB as well, for the the very good tutorial. I’m thinkin of posting more detailed CURL tutorial, as it seems that we have to use it more and more often.

  3. UGGS Sale Says:

    Mostly all the Websites are for the information purpose and you have also created such a great website here.Such a great ideas you have Provided here.Thank you for sharing

  4. cheap christian louboutin shoes Says:

    He engages many cues to this end – their clothing, debris on their skin and hair, their posture, their stance, their musculature, their movements etc.

Leave a Reply

*

Spam Protection by WP-SpamFree

  • Buy free viagra in the uk Without Prescription Doctor. Best Prices. Best Internet.
  • Buy Cheapest side effects of levitra Online Best Internet. Cheap Pharmacy Online.
  • Buy Cheap order cialis soft Online Internet Prices For order cialis soft! Low Prices.
  • Buy Cheapest viagra free trial pack Now Drugs, Health And Beauty. Best Internet.
  • Buy Cheapest cialis 20mg Online Discount Online Pharmacy. Best Prices.
  • Buy Cheapest cheap cialis generic mastercard Online WorldWide Shipping. Guaranteed Shipping.
  • Buying Cheap cheapest cialis online. Offshore Rx, Good Prices. Online Medical Shop.
  • best levitra price Online Without Prescription Low Prices. Best Drugstore.
  • Buy Cheap viagra texas Now Online Prices For viagra texas! Best Internet.
  • Buy Cheap viagra for sex Now Online Prices For viagra for sex! Online Medical Shop.
  • Buy Cheapest cialis canadian pharmacy Online Best Online. Guaranteed Shipping.
  • Buy Cheapest levitra one a day Online Free Viagra Pills! Best Drugstore.
  • Buy Cheap viagra cialis store Now Best Internet. Cheap Prescription Drugs.
  • Buy Cheap is levitra safer than viagra Online Best Prices. No Prescription Needed.
  • Buy Cheap levitra vs viagra Online 24/Online Pharmacy. Best Drugstore.
  • Buy Cheap viagra paypal Now Guaranteed Shipping. Discount Pharmacy Online.
  • Buy Cheap levitra order Now Free Viagra Pills! Pharmacy At The Best Price!
  • Buy Cheap soft tab cialis Now Buy Medications Online. Online Medical Shop.
  • buy female viagra Online Without Prescription Free Viagra Pills! Best Prices.
  • Buy Cheapest levitra free sample Online 24/Online Pharmacy. Best Internet.
  • Buy Cheap cialis does not work Now No Prescription Needed For Drugs. Best Prices.
  • Buy Cheapest free viagra sample Now Best Drugstore. Special Prices For free viagra sample!
  • Buy Cheap order viagra cheap Now Guaranteed Shipping. Cheap Prescription Drugs.
  • Buy Cheap what is cialis professional Now Pharmacy At The Best Price! Pharmacy Store.
  • Buy Cheap canadian levitra Now Cheap Pharmacy Online. Top Online Pharmacy.
  • Buy Cheap cheap levitra Online Best Internet. Discount Pharmacy Online.
  • Buy Cheap cialis usage instructions Now No Prescription Online Pharmacy. Low Prices.
  • Buy Cheap german viagra substitutes Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheap buy viagra cialis levitra online prescription Now Best Drugstore. Discount Online Pharmacy.
  • Buy Cheapest viagra sideffects Online Low Prices. Pharmacy At The Best Price!
  • mail order viagra online Online Without Prescription Best Prices. Best Online.
  • Buy Cheap levitra 20 mg Now Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheap soft viagra Now Pharmacy Store. Order Cheap Meds Without Rx.
  • Buy Cheapest generic soft tab viagra Now Cheap Prescription Drugs. Low Prices.
  • Buy Cheap cialis medicine Now No Prescription Online Pharmacy. Best Prices.
  • Buy Cheapest cialis next day delivery Online Online Medical Shop. Best Internet.
  • Buy Cheap viagra effects on women Now Best Drugstore. No Prescription Needed.
  • Buy Cheapest viagra xanax phentermine online pharmacy Online Best Drugstore. Buy Medications Online.
  • Buy Cheapest online viagra canada Online Low Prices. Internet Prices For online viagra canada!
  • Buy Cheap viagra and ejaculation Now Best Online. All Medications Are Certificated!
  • Buying Cheapest pills viagra. Offshore Pharmacy, Good Prices. Low Prices.
  • Buy Cheap viagra timing Online Top Online Pharmacy. Online Medical Shop.
  • Buy Cheapest lowest price on levitra Now Cheap Prescription Drugs. Best Prices.
  • Buying Cheap viagra cialis levitra reviews. Mexican Pharmacy, Good Prices. Best Drugstore.
  • Buy Cheap where can i buy viagra? Now Cheap Meds Without Prescription. Low Prices.
  • Buy Cheap cheap viagra from pfizer Now Best Online. Safe And Secure Payment System.
  • Buy Cheapest online drug purchase levitra Now Drugs, Health And Beauty. Low Prices.
  • Buy Cheap genaric viagra Now Best Online. All Medications Are Certificated!
  • Buy Cheap viagra best buy Online Top Online Pharmacy. Free Viagra Pills!
  • Buy Cheap 5mg cialis generic Online Cheap Pharmacy Online. Best Internet.
  • Buy Cheap viagra blue Now No Prescription Needed. Pharmacy Store.
  • Buy Cheap levitra or viagra Now Buy Medications Online. Free Viagra Pills!
  • Buy Cheap medication levitra Now Best Drugstore. Discount Pharmacy Online.
  • Buy Cheap levitra effectiness Online Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheap difference between viagra cialas and levitra Online Pharmacy Store. Discount Online Pharmacy.
  • Buy Cheap prescription online levitra cialis viagra Now Pharmacy Store. No Prescription Needed.
  • Buy Cheap generic cheap cialis Online Best Internet. Pharmacy At The Best Price!
  • Buying Cheap viagra in the uk. Offshore Rx, Good Prices. Guaranteed Shipping.
  • Buy Cheap cheap cialis india Now Internet Prices For cheap cialis india! Best Prices.
  • Buy Cheap cialis online canada Online Pharmacy Store. Discount Online Pharmacy.
  • Buy Cheap find viagra online Now FDA Approved Rx: Online Pharmacy. Low Prices.
  • Buy Cheap information on levitra Online Pharmacy Store. Internet Prices For information on levitra!
  • Buy Cheapest ciallis or viagra Now Free Viagra Pills! Online Medical Shop.
  • viagra natural herbs Online Without Prescription Low Prices. Top Online Pharmacy.
  • Buy Cheap lowest prices viagra Now Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheapest active ingredient cialis Now No Prescription Needed. Best Online.
  • Buy Cheap generic viagra india Now 24/Internet)(safe Pharmacy. Low Prices.
  • Buy Cheap viagra vs cialis levitra Online 24/Online Pharmacy. Online Medical Shop.
  • Buy Cheap low dose cialis Online WorldWide Shipping. Buy Medications Online.
  • Buying Cheap online generic viagra. Offshore Rx, Best Prices. Top Online Pharmacy.
  • Buy Cheap cialis buy Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheapest buy viagra canada Online Drugs, Health And Beauty. Best Online.
  • Buy Cheap cialis cheap prices Now Internet Prices For cialis cheap prices! Best Prices.
  • Buy Cheap cialis and blood pressure Now Best Internet. Discount Online Pharmacy.
  • Buy Cheapest natural herbal alternatives to viagra Online Internet Prices For natural herbal alternatives to viagra! Low Prices.
  • levitra vs cialis vs viagra Online Without Prescription Guaranteed Shipping. Low Prices.
  • Buy Cheap buy generic cialis Now WorldWide Shipping. Drugs, Health And Beauty.
  • Buy Cheap buy viagra cialis levitra Now Best Drugstore. Cheap Prescription Drugs.
  • Buy Cheapest buy viagra online cheap Now Cheap Prescription Drugs. Best Prices.
  • Buying Cheap levitra compare viagra. Offshore Rx, Best Prices. Top Online Pharmacy.
  • Buy Cheap viagra blood pressure Now Free Viagra Pills! Pharmacy At The Best Price!
  • Buy Cheapest headache pain propecia relief viagra Now Best Internet. Buy Medications Online.
  • Buy Cheapest cheapest cialis index Online Cheap Online Pharmacy. Low Prices.
  • Buy Cheapest cialis erectile disfunction Now 24/Online Pharmacy. Online Medical Shop.
  • Buy Cheapest cheap viagra order online Online Guaranteed Shipping. Free Viagra Pills!
  • Buy Cheap 10mg levitra Now No Prescription Needed. Guaranteed Shipping.
  • Buy Cheapest generic brands of viagra online Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheap cialis once a day Online Discount Pharmacy Online. Best Prices.
  • Buy Cheap compare cialis viagra Online Top Online Pharmacy Supplier. Low Prices.
  • Buy Cheapest cheap levitra online Now 24/Online Pharmacy. Online Medical Shop.
  • Buy Cheap viagra trial sample Now No Prescription Needed. Pharmacy Store.
  • Buy Cheap online pharmacy generic cialis Online Guaranteed Shipping. Pharmacy Store.
  • Buy Cheap cialis europe Online Pharmacy Store. 24/Online Pharmacy.
  • Buy Cheap viagra vs levitra reviews Now The Largest Internet Pharmacy. Best Internet.
  • Buy Cheapest online viagra Now Best Online. The Largest Internet Pharmacy.
  • Buy Cheap low cost alternatives and viagra Online Pharmacy Store. Online Medical Shop.
  • Buy Cheap find lowest price for cialis Now FDA Approved Rx: Online Pharmacy. Low Prices.
  • Buy Cheap free cialis samples Now Best Prices. 24/Internet)(safe Pharmacy.
  • Buy Cheapest buy viagra on line Online Discount Pharmacy Online. Best Prices.
  • Buy Cheap c-pill cheap cialis Now WorldWide Shipping. Special Prices For c-pill cheap cialis!