title: PHP Server Side Post to Recreate Replace Secure Single Sign On
body: <p>I host and intranet and manager several Single Sign Ons for outside websites.  We have always done this through some sort of hidden form. </p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>&lt;form method="post" action="example.php"&gt;
  &lt;input type="hidden" value="user" name="user" /&gt;  
  &lt;input type="hidden" value="password" name="password" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>We can then have a javascript event submit the hidden form behind the scene and log in the user.</p>
  
  <p>However, a more sophisticated user, who is already authenticated into our site, could view the source and view the user name and password.  </p>
  
  <p>I would prefer to have the information posted from a PHP script to seamlessly log them into the external site.  </p>
  
  <p>I have done a lot of research on the web and have come up with a few consistent lines of code that people implement that don't seem to work.</p>
  
  <p>They usually are similar to the code below:</p>
  
  <pre><code> $ch = curl_init($POSTURL);
   curl_setopt($ch, CURLOPT_POST      ,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS,POSTVARS);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
   curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
   curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
   $Rec_Data = curl_exec($ch);
   curl_close($ch);
  </code></pre>
  
  <p>However, I the authentication does not seem to work . If I try to print what is returned by curl_exec, I don't have any success.  I also am not sure if this would even be the right way to go about it.</p>
  
  <p>I get the following error from my code: </p>
  
  <p><strong>Curl error: error setting certificate verify locations: CAfile: /etc/ssl/certs
     /ca-certificates.crt CApath: none</strong></p>
  
  <p>I don't want to keep the users inside our site, I just want to launch the other site after authenticating them.  If this works in a standard HTML post, I should be able to recreate this ability using server side code. Right?</p>
  
  <p><em>On a side note, I have done something like this in my former life with Coldfusion.  It was much much easier.  Surely PHP and all its users have come up with something!</em></p>