RE: [PHP] post without form

From: Date: Wed, 16 Aug 2000 21:29:43 +0000
Subject: RE: [PHP] post without form
Groups: php.general 
Request: Send a blank email to php-general+get-12117@lists.php.net to get a copy of this message
> $host = "your.host.com"; > $port = 80; > $postdata = "field1=value1&field2=value2&field3=value3"; > if ($sp = fsockopen($host,$port)) { > fputs($sp,"POST /path/to/somescript/php HTTP/1.0\n"); > fputs($sp,"Host: $host\n"); > fputs($sp,"Content-type: application/x-www-form-urlencoded\n"); > fputs($sp,"Content-length: ".strlen($postdata)."\n"); > fputs($sp,"Connection: close\n\n"); > fputs($sp,$postdata); > // optionally print the response > while (!feof($sp)) { > echo fgets($sp,128); > }> fclose($sp); > } I tried out the above and it worked wonderously. However, there are a few things: while (!feof($sp)) { echo fgets($sp,128); } I'm not 100% sure what exactly the above is doing, but what it prints is the header information (ie HTTP/1.1 200 OK Date: Wed, 16 Aug 2000 21:18:08 GMT Server: Apache/1.3.6 Ben- SSL/1.36 (Unix) PHP/3.0.5 Connection: close Content-Type: text/html) along with the data echoed from the second page. How can I keep the above from displaying? While I am interested in the above, what I am most interested in is this: when you pass variables using GET by tacking them onto the end of the file you want to load (ie www.mysite.com/file.php3?var1=joe&var2=b0b), file.php3 is "getting control". From what it appears, the above code seems like it is essentially the same thing as include()ing the second file with the second file never "getting control". Is there any way to submit data to a second file via the POST method, without a form, and sending the browser to that file in one shot? I hope I've been somewhat coherant in what I'm looking for. :p Any information would be greatly appreciated. Chris

« previous php.general (#12117) next »