PHP cURL: GET POST SSL AUTH
PHP cURL : Introduction | Basics | Authentication | SSL | GET & POST | GET POST SSL AUTH | CLI Set-up | CLI DtDNS Updater 1 | CLI DtDNS Updater 2
|
|
UniServer 5-Nano PHP cURL. |
cURL GET POST SSL and Authentication
This page contains no new material what it provides are examples using our test simulation server to accesses a verification server over SSL to submit a form.
It takes the examples from the previous page and adds authentication and SSL.
Preperation
Our verification server curl_2 has already been configured
- A default server certificate and key have been generated
- Appropriate lines in C:\curl_2\UniServer\ssl\.htaccess are enabled
All that remains is to copy C:\curl_2\UniServer\www\remote_form.php to folder C:\curl_2\UniServer\ssl
Perhaps add a line to distinguish the form see last line:
<?php print "<p><b>Method GET</b><br />"; if(isset($_GET['Name'])) $Name = $_GET['Name']; if(isset($_GET['Password'])) $Password = $_GET['Password']; if(isset($_GET['Message'])) $Message = $_GET['Message']; print "Name = $Name<br />"; print "Password = $Password<br />"; print "Message = $Message</p>"; print "<p><b>Method POST</b><br />"; if(isset($_POST['Name'])) $Name = $_POST['Name']; if(isset($_POST['Password'])) $Password = $_POST['Password']; if(isset($_POST['Message'])) $Message = $_POST['Message']; print "Name = $Name<br />"; print "Password = $Password<br />"; print "Message = $Message</p>"; print "<p>SSL TEST FORM</p>"; ?>
Example 12 - cURL GET
Using example 10 add the appropriate target page, password and SSL functions:
- curl_setopt($ch, CURLOPT_URL,'https://localhost:446/remote_form.php');
- curl_setopt($ch, CURLOPT_USERPWD, "root:root");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify
Create a new text file in folder C:\curl_1\UniServer\www and name it test12.php add the following content
|
Test:
|
Results:
|
|
Example 13 - cURL POST
Using example 11 again add the appropriate target page, password and SSL functions:
- curl_setopt($ch, CURLOPT_URL,'https://localhost:446/remote_form.php');
- curl_setopt($ch, CURLOPT_USERPWD, "root:root");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify
Create a new text file in folder C:\curl_1\UniServer\www and name it test13.php add the following content
|
Note: I have included print $str to show what the encoded string looks like Test:
|
Results:
|
|
Summary
The example so far run scripts on a server.
The next page covers how to configure cURL on Uniform Server for portable operation using PHP in CLI mode.