Re: Emulating a POST

From: Date: Fri, 10 Aug 2001 07:51:44 +0000
Subject: Re: Emulating a POST
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62120@lists.php.net to get a copy of this message
hope this helps: /// <?php // simple post method // version 1.0 by Andrus (andrus@vnet.ee) // Disclaimer: // everyone can change or use this code however and wherever they want ;) // send out "browser" headers function send_headers ($fp) { fputs ($fp, "Accept: */*\n"); fputs ($fp, "Accept-Language: en\n"); fputs ($fp, "Connection: Keep-Alive\n"); fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\n"); } // post data and return reply function post_data ($host, $url, $data) { $fp = @fsockopen ($host, 80, $errno, $errstr, 120); $ret = ""; if (strncasecmp ($url, "http://", 7) == 0) $url = substr ($url, 7); $p = strpos ($url, '/'); if (empty ($p)) { $req = "/"; } else { $req = substr ($url, $p); } if ($fp) { fputs ($fp, "POST $req HTTP/1.0\n"); send_headers ($fp); fputs ($fp, "Content-type: application/x-www-form-urlencoded\n"); $out = ""; while (list ($k, $v) = each ($data)) { if(strlen($out) != 0) $out .= "&"; $out .= rawurlencode($k). "=" .rawurlencode($v); } $out = trim ($out); fputs ($fp, "Content-length: ".strlen($out)."\n\n"); fputs ($fp, "$out"); fputs ($fp, "\n"); while(!feof($fp)){ $ret .= fgets($fp,128); } fclose ($fp); } return $ret; } // example how to use: // following code will post variables "login" and "pass" to server "www.something.com" script "/submit.php" $reply = post_data ("www.something.com", "/submit.php", array ("login" => $username, "pass" => $password)); ?> /// "Brandon Orther" <orther@webintellects.com> wrote in message news:00cd01c1204b$d5cdb9b0$0a00a8c0@webintel... > Hello, > > I have used perl to emulate a post with LWP:UserAgent I am looking for > the same effect in php. Does anyone know how I can do this? > Thank you > Brandon > >

« previous php.general (#62120) next »