Jump to content

[SOLVED] Using PHP to POST to other server -- OK, except for response text.


aximbigfan

Recommended Posts

Hi...

 

I have a PHP script that is suppose to post to another server, and then return the response. The big problem here is that it is also returning the headers from the other server, so I put tags around the output, and am tryign to parse what is between the tags. I have that part down, but this simply is not working. The tags are all there, and when the tag code is taken out, it works fine, but it will then output the headers too, which I just don't want as it contaminates the output.

 

So...

1. Can I do something else so that the headers are NOT returned?

2. If not, how can I parse the tags right?

 

 

Here is the code

function remotereg($host, $path, $mode, $cat=null, $key=null, $val=null, $ueo=null )
{
$http_response  = "";
$data           = "mode=$mode&cat=$cat&key=$key&val=$val";
$content_length = strlen($data);
$fp             = fsockopen($host, 80);
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp))
$http_response .= fgets($fp, 28);
fclose($fp);
return $http_response;
//Parse tags
$start = "ret";
$end   = "/ret";
$parsein = http_response;
$parseout = "";
$pos_s = strpos($parsein, $start);
$pos_e = strpos($text, $end);
for ($i=$pos_s+strlen($start) ; (( $i<($pos_e)) && $i <strlen($parsein)) ; $i++)
{
$parseout .= $text[$i];
}
$http_response = $parseout;
return $http_response;
}

 

Thanks!

Chris

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.