On Sun, Apr 08, 2001 at 12:31:35AM -0500, Joseph Bannon wrote:

> > You can use fopen/fread to open the script remotely.
> > 
> > Just append the query string onto the url something like this:
> > 
> > www.example.com/example.php?var1=var
> > 
> > ...and example.php will have $var1 with the value "var". That's basically
> > like using GET on a form.
> > 
> > I believe that's what you wanted to do?
> 
> I have to use POST on the form. I wish I could use GET.

For that, you'll need to open a socket.  The function to do this is
usually called PostToHost, and I don't know why it isn't in even the
annoted manual page for fsockopen.  A quick google search should turn
up copies of it in all the PHP mailing list archives.  But, here's the
version that I use (It's been modified to support both GET and POST):

function sendToHost($host,$method,$path,$data,$useragent=0)
{
   // Supply a default method of GET if the one passed was empty
   if (empty($method))
      $method = 'GET';
   $method = strtoupper($method);
   $fp = fsockopen($host,80);
   if ($method == 'GET')
      $path .= '?' . $data;
   fputs($fp, "$method $path HTTP/1.1\n");
   fputs($fp, "Host: $host\n");
   fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
   fputs($fp, "Content-length: " . strlen($data) . "\n");
   if ($useragent)
      fputs($fp, "User-Agent: MSIE\n");
   fputs($fp, "Connection: close\n\n");
   if ($method == 'POST')
      fputs($fp, $data);

   while (!feof($fp))
      $buf .= fgets($fp,128);
   fclose($fp);
   return $buf;
}

$data should be the variables of the query string, minus the question
mark.  That is, var1=value1&var2=value2, etc.  The function doesn't
encode it, so you'll need to do that.

HTH,
Matt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to