views:

32

answers:

2

I'm trying to make the code below work with curl or something. I have already taken a look at the curl fsockopen conversion but it doesn't work. The code works except that fsockopen is disabled on my host. Any help will be appreciated.

$host = substr($hostport,0,50);
$port = substr($hostport,50,10);
$issecure = substr($hostport,60,1);

if($issecure=="Y")
{
    $host = "ssl://".$host;
}
$fsok = fsockopen(trim($host) , intval(trim($port))); 
if(FALSE == $fsok )
{
    echo "Target Host not Found/Down"; return ;
}
fwrite($fsok, $bodyData ); 
$port ='';$host ='';$hostport= '';$bodyData='';

while ($line = fread($fsok, 25000))
{
    echo $line;
}

fclose($fsok); 
return $line;
+1  A: 

Assuming youre using http/https as the protocol somethig like the following should work:

$client = curl_init();

$options = array(
  CURLOPT_PORT => $port
  CURLOPT_RENTURNTRANSFER => true,
  CURLOPT_SSL_VERIFYPEER => false, // dont verify the cert
  CURLOPT_URL => ($issecure ? 'https://' : 'http://'). $host
);

$response = curl_exec($client);

if(false !== $response) {
  echo $response;
  return $response;
} else {
  if($error = curl_error($client)) {
    echo $error;
    return $error;
  } else {
    echo 'Something is wrong. Error could not be determined.';
  }
}

Another great and much eaiser to use option would be Zend_Http_Client it supports fsockopen, and curl so you can switch back and forth quite easily without modifying code.

prodigitalson
@prodigitalson: Sorry for late reply, was trying to see if it would work but it's writing target host not found.. Please I'll paste the full code for you.. thanks
Jade
A: 
Jade