fsockopen to conect to ssl sites
| From: | Jorge Castaneda | Date: | Sat, 03 Jan 2004 17:06:49 +0000 |
| Subject: | fsockopen to conect to ssl sites | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173690@lists.php.net to get a copy of this message | ||
WHERE IS THE ERROR?
The username and the password are the correct and the name of the
variables (login and pass) also match. I tried to get data from a
secure site but I always receive the next message instead of the page
I request:
We are connected with somesecuredomain.com
HTTP/1.1 302 Found Date: Fri, 02 Jan 2004 19:21:20 GMT Server:
Apache/1.3.27 (Unix) FrontPage/5.0.2.2623 PHP/4.3.2 mod_gzip/1.3.19.1a
mod_accounting/1.0 mod_fastcgi/2.4.0 mod_ssl/2.8.14 OpenSSL/0.9.7b
rus/PL30.17 X-Powered-By: PHP/4.3.2 Set-Cookie:
biz=8a204f6cf271a7a81d3de70c0b250921; path=/ Expires: Thu, 01 Jan 1970
00:00:01 GMT Cache-Control: no-store, no-cache, must-revalidate,
post-check=0, pre-check=0 Pragma: no-cache Location:
/?error=Auth+error%2C+wrong+login+or+password.&login=myusername
Connection: close Content-Type: text/html; charset=windows-1251
Last-Modified: Fri, 02 Jan 2004 19:21:20 GMT
The script I used:
__________________________________________
<?php
$host= "somesecuredomain.com"; $page= "/account/login.php";
$formdata = array (login=>"myusername" , pass=>"mypassword");
foreach($formdata AS $key => $val)
{
$poststring .= urlencode($key)."=".urlencode($val)."&";
}
$poststring = substr($poststring, 0, -1);
$request= "POST $page HTTP/1.0\x0D\x0A";
$request .= "HOST: $host\x0D\x0A";
$request .= "Content-Type: application/x-www-form-urlencoded\x0D\x0A";
$request .= "User-Agent: test client\x0D\x0A";
$request .= "Accept: */*\x0D\x0A";
$request .= "Content-Length: ".strlen($poststring)."\x0D\x0A";
$request .= "Connection: close\x0D\x0A\x0D\x0A";
$request .= $poststring ."\x0D\x0A\x0D\x0A";
$fp = fsockopen("ssl://".$host, 443, &$errorno, &$errordesc);
if ($fp) {print "We are connected with $host";}
else
{die ("I can not connect with $host: \nError: $errorno \nDescription: $errordesc");}
print "<br>";
fputs($fp, $request);
while (!feof($fp))
print fgets($fp, 1024);
fclose($fp);
?>
___________________________________________________________________________________
Thank you in advance for any help.
Best regards,
Jorge mailto:jorge@wgi.ru