I host and intranet and manager several Single Sign Ons for outside websites. We have always done this through some sort of hidden form.
Example
<form method="post" action="example.php">
<input type="hidden" value="user" name="user" />
<input type="hidden" value="password" name="password" />
</form>
We can then have a javascript event submit the hidden form behind the scene and log in the user.
However, a more sophisticated user, who is already authenticated into our site, could view the source and view the user name and password.
I would prefer to have the information posted from a PHP script to seamlessly log them into the external site.
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.
They usually are similar to the code below:
$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);
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.
I get the following error from my code:
Curl error: error setting certificate verify locations: CAfile: /etc/ssl/certs /ca-certificates.crt CApath: none
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?
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!