Bluehost.com Web Hosting $6.95

fsockopen to conect to ssl sites

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-03-2004
Jorge Castaneda
 
Posts: n/a
Default fsockopen to conect to ssl sites

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
Reply With Quote
  #2 (permalink)  
Old 01-04-2004
Calico Jack
 
Posts: n/a
Default Re: fsockopen to conect to ssl sites

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/

Reply With Quote
  #3 (permalink)  
Old 01-06-2004
Manuel Lemos
 
Posts: n/a
Default Re: fsockopen to conect to ssl sites

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:59 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0