This is a discussion on fsockopen to conect to ssl sites within the PHP General forums, part of the PHP Programming Forums category; WHERE IS THE ERROR? The username and the password are the correct and the name of the variables (login and ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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.&logi n=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 |
|
|||
|
Jorge Castaneda wrote:
> 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.&logi n=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 Have you considered the fact that secure servers AKA https use ENCRYPTION? That is the whole point of a secure server, not just password protection. You need to take a look at the PHP SSL functions. -- -Calico Jack- http://www.scriptsharks.com/ |
|
|||
|
Hello,
On 01/03/2004 03:06 PM, Jorge Castaneda wrote: > 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.&logi n=myusername > Connection: close Content-Type: text/html; charset=windows-1251 > Last-Modified: Fri, 02 Jan 2004 19:21:20 GMT These are headers to redirect you to a login page. You are probably not sending any session cookies that let the site reckon you as logged user. In that case, you need to submit a login form and collect the cookies to be used in the pages that you want to access. You may want to try this class that can do that work of collecting cookies and sending them back when accessing the site pages. There is an example to do that in the same site where the class is available. http://www.phpclasses.org/httpclient -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ |