Page 1 of 1

Sending to external CGI

Posted: Sun Jul 04, 2004 5:46 pm
by mshita
Here is a little more complex question than my previous ones:

I need my PHP code to send a form to cgi script located in entirely different web server. But here is the thing, the php page is not viewed on any regular browser. It is invoked by an embedded device.

The PHP script needs to retrieve data from a database and send that date to the cgi script and then read the result sent from the cgi script, which is then echo'd onto the php file sent back to the embedded device.

I know how to retrieve data from MySQL and process it. But what I'm stumped about is how do I send the data to that cgi script and read the result. Can anyone give me any pointers?

Cheers,
Mounir

Posted: Sun Jul 04, 2004 6:02 pm
by ol4pr0
If its not tomuch data you could use the url itself to send it over.

page.php?data1=1&data2=2.........

Posted: Sun Jul 04, 2004 6:04 pm
by mshita
I can't. It has to be POST method and I can't re-direct the browser simply because there is no browser. Everything has to happend inside my php script.

Posted: Sun Jul 04, 2004 6:10 pm
by ol4pr0
Just did some googling, i found alot of methods to transfer you data to the cgi using CURL and fopen if i am not mistaken

Posted: Sun Jul 04, 2004 6:12 pm
by mshita
fopen? CURL I've heard of, but trying to avoid since I have no idea on how to program curl. Want to try and stick to PHP since I'm in the process of learning it.

Posted: Sun Jul 04, 2004 6:14 pm
by ol4pr0

Posted: Sun Jul 04, 2004 7:53 pm
by mshita
Thanks, looking into it.

Posted: Sun Jul 04, 2004 8:42 pm
by mshita
Don't you have to tell the system the path to the curl library? How do you do that?

Posted: Sun Jul 04, 2004 9:06 pm
by ol4pr0
For as far as i know, you only have to compile php with curl. or include the library if on windows

Posted: Sun Jul 04, 2004 9:07 pm
by mshita
oh okay, thanks. I will try that as soon as I get infront of my computer tomorrow :)

Posted: Sun Jul 04, 2004 9:15 pm
by redmonkey
If you are using a precompiled PHP version on windoze you will need the zip package (as this contains the extra extensions).

The php_curl.dll also depends on ssleay32.dll and libeay32.dll which are also distributed in the zip package although the later two dlls must reside in your system's path.

If you are on any other platform and using precompiled binaries you will probably just have to enable the extension, but failing that you will have to compile cURL first then compile PHP with cURL support at configure time.

Posted: Sun Jul 04, 2004 9:19 pm
by mshita
All I know is that my web hosting company is using Linux and PHP 4 and that they have CURL too.

Posted: Sun Jul 04, 2004 9:29 pm
by ol4pr0

Code: Select all

curl_exec();
that should work fine than

Posted: Sun Jul 04, 2004 9:30 pm
by mshita
Cool. Thanks!