note 49938 added to function.fsockopen

From: Date: Sat, 12 Feb 2005 21:34:24 +0000
Subject: note 49938 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-84906@lists.php.net to get a copy of this message
The documentation example is of a GET request. I have found POST documentation to be lacking, and here's a function to easily simulate submitting form data: <?php # $host includes host and path and filename # ex: "myserver.com/this/is/path/to/file.php" # $query is the POST query data # ex: "a=thisstring&number=46&string=thatstring # $others is any extra headers you want to send # ex: "Accept-Encoding: compress, gzip\r\n" function post($host,$query,$others=''){ $path=explode('/',$host); $host=$path[0]; unset($path[0]); $path='/'.(implode('/',$path)); $post="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n${others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query"; $h=fsockopen($host,80); fwrite($h,$post); for($a=0,$r='';!$a;){ $b=fread($h,8192); $r.=$b; $a=(($b=='')?1:0); } fclose($h); return $r; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49938 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49938&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49938&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49938&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49938&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49938&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49938&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84906) next »