https://wiki.uniformserver.com/index.php?title=PHP_cURL:_GET_POST_SSL_AUTH&feed=atom&action=historyPHP cURL: GET POST SSL AUTH - Revision history2024-03-29T06:01:07ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=PHP_cURL:_GET_POST_SSL_AUTH&diff=3887&oldid=prevRic: New page: {{Nav 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 se...2009-09-11T20:03:12Z<p>New page: {{Nav 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 se...</p>
<p><b>New page</b></p><div>{{Nav PHP cURL}}<br />
'''cURL GET POST SSL and Authentication'''<br />
<br />
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.<br />
<br />
It takes the examples from the previous page and adds authentication and SSL.<br />
<br />
== Preperation ==<br />
Our verification server curl_2 has already been configured<br />
<br />
* A default server certificate and key have been generated<br />
* Appropriate lines in C:\curl_2\UniServer\ssl\.htaccess are enabled<br />
<br />
All that remains is to copy C:\curl_2\UniServer\www\'''remote_form.php''' to folder C:\curl_2\UniServer\'''ssl'''<br />
<br />
Perhaps add a line to distinguish the form see last line:<br />
<pre><br />
<?php<br />
print "<p><b>Method GET</b><br />";<br />
if(isset($_GET['Name'])) $Name = $_GET['Name'];<br />
if(isset($_GET['Password'])) $Password = $_GET['Password'];<br />
if(isset($_GET['Message'])) $Message = $_GET['Message'];<br />
print "Name = $Name<br />";<br />
print "Password = $Password<br />";<br />
print "Message = $Message</p>";<br />
<br />
print "<p><b>Method POST</b><br />";<br />
if(isset($_POST['Name'])) $Name = $_POST['Name'];<br />
if(isset($_POST['Password'])) $Password = $_POST['Password'];<br />
if(isset($_POST['Message'])) $Message = $_POST['Message'];<br />
print "Name = $Name<br />";<br />
print "Password = $Password<br />";<br />
print "Message = $Message</p>";<br />
print "<p>SSL TEST FORM</p>";<br />
?><br />
</pre><br />
<br />
== Example 12 - cURL GET ==<br />
Using example 10 add the appropriate target page, password and SSL functions:<br />
<br />
* curl_setopt($ch, CURLOPT_URL,'<nowiki>https:</nowiki>//localhost:446/remote_form.php');<br />
* curl_setopt($ch, CURLOPT_USERPWD, "root:root");<br />
* curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify<br />
<br />
Create a new text file in folder C:\curl_1\UniServer\'''www''' and name it '''test12.php''' add the following content<br />
{|<br />
|-valign="top"<br />
|<br />
{|cellspacing="6"<br />
|-<br />
|<br />
<pre><br />
<?php<br />
$name_val = urlencode('MPG RIC');<br />
$password_val = urlencode('fred 123');<br />
$message_val = urlencode('This is a test & = ?');<br />
<br />
$str= "?Name=".$name_val."&Password=".$password_val."&Message=".$message_val;<br />
<br />
print $str;<br />
<br />
$ch=curl_init();<br />
curl_setopt($ch, CURLOPT_URL,'https://localhost:446/remote_form.php'.$str);<br />
curl_setopt($ch, CURLOPT_USERPWD, "root:root");<br />
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify<br />
curl_exec($ch);<br />
curl_close($ch);<br />
?><br />
</pre><br />
|}<br />
|<br />
&nbsp;<br /><br />
* First three lines URL encode the values we wish to send.<br />
* Full string '''$str''' is assembled into correct format name value pairs.<br />
* This string is concatenated with the URL (tacked onto the end) <br />
<br />
* Added new URL remember is https and the port must be included<br />
* Added CURLOPT_USERPWD again defaults are root root<br />
* CURLOPT_SSL_VERIFYPEER disabled<br />
<br />
'''''Test'':'''<br />
* Run both servers<br />
* Type '''<nowiki>http:</nowiki>//localhost/test12.php''' into your browser<br />
* Result: Shown below<br />
|}<br />
'''''Results'':'''<br />
{|<br />
|-valign="top"<br />
|<br />
{|<br />
|-<br />
|<br />
<pre><br />
?Name=MPG+RIC&Password=fred+123&Message=This+is+a+test+%26+%3D+%3F<br />
<br />
Method GET<br />
Name = MPG RIC<br />
Password = fred 123<br />
Message = This is a test & = ?<br />
<br />
Method POST<br />
Name = MPG RIC<br />
Password = fred 123<br />
Message = This is a test & = ?<br />
<br />
SSL TEST FORM<br />
</pre><br />
|}<br />
|<br />
&nbsp;<br /><br />
* '''''Note 1'':''' The encoding of & = ? as %26+%3D+%3F (+ is a special character if we used that it would have been encoded)<br />
<br />
<br />
* '''''Note 2'':''' Although we used GET to send data for some reason PHP has mapped the variables in both GET and POST super-globals (I think this is incorrect!).<br />
<br />
<br />
* '''''Note 3'':''' SSL TEST FORM displayed hence correct form picked-up<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Example 13 - cURL POST ==<br />
Using example 11 again add the appropriate target page, password and SSL functions:<br />
<br />
* curl_setopt($ch, CURLOPT_URL,'<nowiki>https:</nowiki>//localhost:446/remote_form.php');<br />
* curl_setopt($ch, CURLOPT_USERPWD, "root:root");<br />
* curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify<br />
<br />
Create a new text file in folder C:\curl_1\UniServer\'''www''' and name it '''test13.php''' add the following content<br />
{|<br />
|-valign="top"<br />
|<br />
{|cellspacing="6"<br />
|-<br />
|<br />
<pre><br />
<?php<br />
$name_val = urlencode('MPG RIC');<br />
$password_val = urlencode('fred 123');<br />
$message_val = urlencode('This is a test & = +');<br />
<br />
$str= "Name=".$name_val."&Password=".$password_val."&Message=".$message_val;<br />
<br />
print $str;<br />
<br />
$ch=curl_init();<br />
curl_setopt($ch, CURLOPT_URL,'https://localhost:446/remote_form.php');<br />
curl_setopt($ch, CURLOPT_USERPWD, "root:root");<br />
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify<br />
curl_setopt($ch, CURLOPT_POST, 1);<br />
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);<br />
<br />
curl_exec($ch);<br />
curl_close($ch);<br />
?><br />
</pre><br />
|}<br />
|<br />
&nbsp;<br /><br />
* First three lines URL encode the values we wish to send.<br />
* Full string '''$str''' is assembled into correct format name value pairs.<br />
* Added new URL remember is https and the port must be included<br />
* Added CURLOPT_USERPWD again defaults are root root<br />
* CURLOPT_SSL_VERIFYPEER disabled <br />
* '''CURLOPT_POST''' Switches to POST operation<br />
* '''CURLOPT_POSTFIELDS''' Informs Curl we are using a value of $str<br />
* This string has been URL encoded. <br />
<br />
'''''Note'':''' I have included '''print $str''' to show what the encoded string looks like<br />
<br />
'''''Test'':'''<br />
* Run both servers<br />
* Type '''<nowiki>http:</nowiki>//localhost/test13.php''' into your browser<br />
* Result: Shown below<br />
|}<br />
'''''Results'':'''<br />
{|<br />
|-valign="top"<br />
|<br />
{|<br />
|-<br />
|<br />
<pre><br />
Name=MPG+RIC&Password=fred+123&Message=This+is+a+test+%26+%3D+%2B<br />
<br />
Method GET<br />
Name =<br />
Password =<br />
Message =<br />
<br />
Method POST<br />
Name = MPG RIC<br />
Password = fred 123<br />
Message = This is a test & = +<br />
<br />
SSL TEST FORM<br />
</pre><br />
|}<br />
|<br />
&nbsp;<br /><br />
* '''''Note 1'':''' The encoding of & = + as %26+%3D+%2B (+ is a special character hence encoded as %2B)<br />
<br />
<br />
* '''''Note 2'':''' Results in POST section as expected (no values in GET which is correct).<br />
<br />
<br />
* '''''Note 3'':''' SSL TEST FORM displayed hence correct form picked-up <br />
<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
The example so far run scripts on a server. <br />
<br />
The [[PHP cURL: CLI Set-up | '''next page''']] covers how to configure cURL on Uniform Server for portable operation using PHP in CLI mode. <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric