mysql copy entire database to remote host
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);

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

Leave a Reply

Spam Protection by WP-SpamFree

  • generic name viagra
  • viagra trial pack
  • european online pharmacy
  • new stop smoking medication
  • health vitamins
  • online discount pharmacy
  • pet ear infection remedies
  • pain management drugs
  • nerve pain remedy
  • organic vitamins
  • antibiotic overdose
  • how to lower high blood pressure
  • bone muscle pain
  • cancer medicine
  • effexor dosages
  • latest treatment for heart attack
  • buy brand names drugs
  • allegra drug
  • heart chest pain
  • bactrim online
  • tretinoin retin a
  • discount medication
  • clonazepam treatment
  • genaric viagra
  • taking diflucan
  • what can help heart failure
  • no prescription pain
  • how to relieve back pain
  • levitra side affects
  • dog health advice
  • leukemia medications
  • congestive heart failure online
  • help reduce high blood pressure
  • levitra warfarin
  • free ultram
  • treating aids in africa
  • how can i stop smoking
  • on-line drugs
  • benadryl dosage
  • prevention of hypertension
  • buy cialis online viagra
  • cialis herbal
  • flu shot
  • buy cialis tadalafil
  • what is elavil
  • weight loss information
  • male enhancements
  • aspirin therapy
  • strengthen immune system
  • viagra women
  • dog antibiotics
  • us online pharmacies
  • nolvadex generic
  • benicar generic
  • do diet pills work
  • parasite killer human
  • treatment of chlamydia
  • what valium does
  • weight loss stuff for free
  • cialis cheapest
  • natural health for dogs
  • arthritis pain medicine
  • gout cures
  • high blood pressure prevention
  • cla buy
  • pet ear infection remedies
  • generic 5mg proscar cheap
  • cheap impotence drug generic cialis delivery
  • weight loss pill that works
  • allergy medication
  • new weight loss drug
  • natural antibiotic anti-biotic
  • diabetes prevention
  • rheumatoid arthritis medications
  • medication gonorrhea
  • alzheimers meds
  • cialis benefits
  • medications ativan
  • drug hydroxyzine
  • meds without prescriptions
  • mens health supplements
  • baby acne
  • birth control online
  • pet supplies products
  • do diet pills work
  • cheap viagra soft
  • nexium use
  • cialis versus viagra
  • female health problems
  • abnormal blood clots
  • buy cialis without a prescription
  • breast augmentation info
  • new drugs for depression
  • arthritis pain medicine
  • cholesterol canada
  • what is hoodia
  • osteoporosis help
  • abscess infection cats
  • health products for men
  • treatment for high blood pressure
  • levitra generic
  • treatment of breast cancer
  • mobic tablets
  • strattera pharmacy
  • drug sarafem
  • carisoprodol dosage
  • women's health tips
  • viagra from usa
  • chest pain
  • allergy medicine
  • blood clots lungs
  • buy drugs online
  • teeth whitening methods
  • buying prescription drugs online
  • how to lower blood sugar
  • parkinson's drugs
  • lexapro info
  • asthma asthma
  • cialis 50mg
  • new levitra
  • severe hair loss
  • pain medication safe while pregnant
  • male health vitamins
  • otc sleep aids
  • vitamin b-12
  • high blood pressure treatment
  • carisoprodol medication
  • living with heart failure
  • diabetes cure
  • women body building
  • cat's health
  • buspirone dosage
  • diet for high blood pressure
  • generic viagra lowest price
  • bupropion 150 mg
  • information on gout
  • what does clomid do
  • medication price
  • weight loss tablet
  • top weight loss drugs
  • discount skin care
  • amitriptyline uses
  • where to buy cialis
  • online cheap soma
  • order alli
  • stomach pain
  • xanax price
  • buy canadian drugs
  • bronchitis medications
  • weight loss tablet
  • pet safety products
  • preventing bone loss
  • advice care health pet uk
  • discount pharmacies in canada
  • natural sleep aid
  • super flu
  • prostate cancer treatment
  • treating dependent edema
  • herbs for impotence
  • wrinkle reducers
  • cheapest cialis generic
  • cheapest cialis uk
  • dog health care
  • cialis 5
  • smoking cessation programs
  • generic online ultram
  • adhd in children
  • valium high
  • pet safety products
  • medicines for insomnia
  • human parasite
  • simvastatin tablets
  • free diabetes products
  • online prescription pharmacy
  • pet med
  • purchase vitamins
  • penis enlargement result
  • medication skelaxin
  • buy body building supplement
  • burning fat
  • left side pain
  • depression drugs
  • pain drugs
  • tramadol and dosage
  • discount weight loss prescription
  • weight loss exercise tips
  • drugs online
  • teeth white
  • stop smoke
  • sildenafil online
  • professional viagra
  • blockers calcium channel
  • avapro 150mg
  • fda levitra
  • blue pills
  • pain medicine online ordering
  • male health drugs
  • chronic congestive heart failure
  • normal blood pressure
  • stronger erections