fsockopen cannot receive post data on localhost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Perseas
Forum Newbie
Posts: 1
Joined: Fri May 01, 2009 11:59 am

fsockopen cannot receive post data on localhost

Post by Perseas »

Hi i am relative new to php,
on my own apache server (localhost), i use one .php script to 'post' data to another .php script also on my server. The problem is that although the http request reaches the receiving script, it seems that there is no posted data.

The code on the sending page is:

Code: Select all

<?php
 
$req = "&One=Ena&Two=Dyo&Three=Tria";
$req = urlencode($req);
$header = "POST /main/php/Receive.php HTTP/1.1\r\n";
$header .= "Host: localhost\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= $req;
 
 
$fp = fsockopen ('localhost', 8000, $errno, $errstr,2);
             if (!$fp) { $message ="// HTTP connection ERROR!"; echo $message; exit;}
             else {
                  fputs ($fp, $header);
                  echo "Success on fputs!<br/>";
 
                  while (!feof($fp) )
                      {
                       $res[$i] = fgets($fp,1024);
                       echo "RESULTs :".count($res)."<br/>";
                       echo 'Res['.$i.'] ='.$res[$i]."<br/>";
                       $i++;
                      }
                 }
fclose($fp);
 
?>

while the code on the receiving script is:

Code: Select all

<?php
 
$result = 'NULL';
 
foreach( $_POST as $key => $value ) // also tried $_REQUEST
                { $result .= $value; }
///// then i write the $result on a MYSQL table
 ?>
On each execution of the sending script, the receiving script is triggered. I know this, because a new insertion of $result is entered in mysql, but it is allways an emty string.
I checked the $_POST with other ways also, but it still is empty.
Please advise what am i doing wrong. Any help appreciated.
Last edited by Benjamin on Fri May 01, 2009 12:44 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply