Question in posting form-data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, all,

I am testing how to post form-data to a host using the following code (test.php):

<?php
        function PostToHost($host, $path, $name, $value) {  // Test of posting form-data
  		$fp = fsockopen($host,80);  		

  		fputs($fp, "POST $path HTTP/1.1\n");
  		fputs($fp, "Host: $host\n");
  		fputs($fp, "Content-Type: multipart/form-data\n");
 		fputs($fp, "content-disposition: form-data; name=$name\n");
  		fputs($fp, "Connection: close\n\n");

  		fputs($fp, "$value\n");

  		$res = "";
		while(!feof($fp)) {
      		$res .= fgets($fp, 128);
  		}
  		
  		fclose($fp);

  		return $res;
	}


        $host = "my.host";
        $path = "/path/to/receive.php";
        $name = "x";
        $value = "ABC"; 


        $returnedValue = PostToHost($host, $path, $name, $value);

        echo $returnedValue;

?>

receive.php goes like this,
<?php
    echo 'x = '.$_POST['x'].'; <br />';
?>

I got,
..........

Notice:  Undefined index:  x in /export/home/mydir/www/test.php on line 2

x = ; 


It looks like receive.php didn't receive the posted value. Is there anything wrong with the program? Thanks in advance for any help.

-Minghua




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux