RE: [PHP] post without form

From: Date: Wed, 16 Aug 2000 18:17:56 +0000
Subject: RE: [PHP] post without form
Groups: php.general 
Request: Send a blank email to php-general+get-12085@lists.php.net to get a copy of this message
This was posted to the list not too long ago. I assume that the original author (Joe Conway)doesn't mind the repost... (please correct me if I'm wrong, however). -----Original Message----- From: Joe Conway [mailto:jconway2@home.com] Sent: Monday, August 14, 2000 9:12 PM To: John Portwin; php-general@lists.php.net Subject: Re: [PHP] POST from within a script? >I am trying to write a script that will go through an array of orders and >start a separate HTTP connection (to execute a CGI on another server on the >internet) for each one. > Here's a quick and dirty function to conditionally GET or POST depending on desired method. $request is a string of the variables being passed, i.e. var1=foo&var2=bar. $rsf is an array of values from a PostgreSQL query which includes the URL of the target page. Hope this helps -- Joe <? function process_submission($request,$rsf) { $request = substr($request,0,strlen($request)-1); print("Request: " . $request . "<br>\n"); // Build the header $tgt = substr($rsf["target_url"],strpos($rsf["target_url"],"/" ,7)); print("Target: " . $tgt . "<br>\n"); flush(); if (strtoupper($rsf["target_method"])=="POST") { $header = "POST " . $tgt . " HTTP/1.0\r\n"; $header .= "Content-type: application/x-www-form-urlencoded\r\n"; $header .= "Content-length: " . strlen($request) . "\r\n\r\n"; } else { $header = "GET " . $tgt . "?" . $request . " HTTP/1.0\r\n\r\n"; }; print("Header: " . $header . "<br>\n"); flush(); // Open the connection $host = substr($rsf["target_url"],7,strpos($rsf["target_url"],"/" ,7) - 7); print("Host: " . $host . "<br><hr>\n"); flush(); $fp = fsockopen($host, 80, &$err_num, &$err_msg, 30); if ($fp) { // Send everything if (strtoupper($rsf["target_method"])=="POST") { fputs($fp, $header . $request); } else { fputs($fp, $header); }; // Get the response print("Response:<br><hr>\n"); flush(); while (!feof($fp)) { $response = fgets($fp, 128); print($response); flush(); }; print("<br><hr>\n"); flush(); }; }; ---- > -----Original Message----- > From: Martin A. Marques [mailto:martin@math.unl.edu.ar] > Sent: Wednesday, August 16, 2000 11:59 AM > To: Steven Werby > Cc: php-general@lists.php.net > Subject: Re: [PHP] post without form > > > On Wed, 16 Aug 2000, Steven Werby wrote: > > > Martin A. Marques <martin@math.unl.edu.ar> wrote: > > > Is it posible to post certain variables without using a form? > > > I need a Location to send with it some variables, but > don't know how to do > > > it. Is it posible? > > > > Sure. > > > > $var1 = "15"; > > $var2 = "widgets"; > > $url = > > "http://host.domain.tld/dir/file.php?var1=\"$var1\"&var2=\"$var2\""; > > Sorry for the information that I didn't add. I don't want the > variables > to appear in the URL. I want it to be passed like if it was a > form with > method=post. Is this posible? > > > > "And I'm happy, because you make me feel good, about me." - > Melvin Udall > ----------------------------------------------------------------- > Martín Marqués email: martin@math.unl.edu.ar > Santa Fe - Argentina http://math.unl.edu.ar/~martin/ > Administrador de sistemas en math.unl.edu.ar > ----------------------------------------------------------------- > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net >

« previous php.general (#12085) next »