This should help you. It is the fsockopen version of what I posed about 6 
hours ago.

function getdata ($host, $port, $data)
{
        $fp = fsockopen ( $host, $port, $ec, $es, 5.0);
        if ( !$fp )
        {
                exit ("ERROR $ec: $es\n");
        }
        fputs ($fp, $data);
        while ( !feof($fp) )
        {
                $buffer = fgets ($fp,128);
                $string .= $buffer;
        }
        fclose ($fp);

        return $string;
}


sends $data to $host:$port and returns the response, until the connection is 
severed. something like getdata ("www.php.net", 80, "GET / 
HTTP/1.0\r\n\r\n") should work out well for you



On Monday 04 February 2002 07:15, you wrote:
> Hi,
>
> I am trying to access a remote file by opening a socket on port 80 but keep
> getting refused...
>
> The server does listen on port 80 as i can access it via browser...
>
> my code reads like this:
> <?php
> $Destination =
> "http://srv157:7001/Palmeira2Application/palmeira2.servlets.communicator.Co
>m municator";
> $Request = "action=$action&username=$uname&password=$password";
> $cfgTimeOut = 20;
>
> $theURL = parse_url($Destination);
> $host = $theURL["host"];
> $path = $theURL["path"];
> $port = $theURL["port"]; if ($port=="") $port=80;
> $header = "POST ".$path." HTTP/1.0\r\n";
> $header .= "Host: ".$host."\r\n";
> $header .= "Accept: */*\r\n";
> $header .= "Accept-Language: en\r\n";
> $header .= "User-Agent: PHP/4.0.6 (Apache/1.3.20)\r\n";
> $header .= "Content-Type: text/xml\r\n";
> $header .= "Content-Length: ".strlen($Request)."\r\n";
> $header .= "Content: \r\n\r\n";
> $msg = $header. $Request ;
> $Response = "";
>
> echo $port;
> //echo $host;
>
> // open a socket
> if(!$cfgTimeOut)
> // without timeout
> $fp = fsockopen($host,$port);
> else
> // with timeout
> $fp = fsockopen($host,$port, &$errno, &$errstr, $cfgTimeOut);
>
>
> if ($fp) {
> if (!fputs($fp,$msg,strlen($msg))) { return false; } // S E N D
>
> while (!feof($fp)) {$Response .= fgets($fp,32768);}
>
> fclose($fp); // R E C E I V E
>
> } else
> {
> echo "Unable to access (".$Destination.").<br>";
>
> echo "<a href=\"javascript:history.go(-1)\">Try another</a>";}
>
> print "$response\n";
>
> print "hello";
> ?>
>
> any suggestions pl??
>
> TIa,
> sands

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to