If I understand it, you COULD simply have a page with a form that points to
the CGI script, but you want to simulate this instead, correct?

If this is the case, you need to send that data as part of the HTTP headers
when requesting the page (instead of simply fputs-ing the GET / HTTP/1.1 or
whatever).  You can either extend the URI with the data (request the file
"cgi-bin/script?foo=bar&var=other") in other words, a simulation of <FORM
METHOD="GET">. fputs() something like:

GET /cgi-bin/script?foo=bar&var=other HTTP/1.1
(two \n's to end the headers)

The other option (simulating <FORM METHOD="POST"> is to make a POST request
to the server instead of a GET, followed by the data.  You'd fputs()
something like:

POST /cgi-bin/script HTTP/1.0
Content-type: application/x-www-form-urlencoded
Content-length: 200 (I think this just needs to be longer than all the data)
(blank line here)
foo=bar
var=other
(two \n's to end the headers)

I _think_ it sounds like you've already accomplished this.  The next step is
to read the data coming back from the cgi script and echo it to your php
output.  There are a few niggling things in my mind, such as a server
redirect possibly happening, so you would have to test the headers that came
back from the cgi script.  If it's a 200 OK message, then you can feel free
to just echo the html.  I think you could probably use fpassthru() or
something similar (although I think this is quite a resource hog for large
files, and you're probably best reading it line at a time
($reading=fread($socket_name, 4096); followed by an echo $reading; until the
end of the file).

Hope that helps!

Ross



-----Original Message-----
From: Rich Gray [mailto:[EMAIL PROTECTED]]
Sent: 11 July 2002 14:04
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] Formless post question


I am doing a formless post to a CGI script on another site (PayPal). I am
doing this because the current site design has 2 different submit images on
a single form which need to post different data to the CGI script (after
registering the customer in the local database) dependent upon whcih image
gets clicked.

The PayPal CGI script has user interaction - the user has to login.

I am doing the formless post by using fsockopen() and fputs() to open the
http port and posting the data which seems to be working fine...and I
receive the raw http headers and html code when I read the open socket...
now for the $64m question - how can I emulate a normal form submit in
actually *loading* the page that is sent by the CGI script in the normal
fashion? If I don't read the data on the open socket then my script just
dies with no output...

Am I trying to do something very stupid here? :)

TIA
Rich


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to