Sending to external CGI

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Sending to external CGI

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

If its not tomuch data you could use the url itself to send it over.

page.php?data1=1&data2=2.........
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post by mshita »

Thanks, looking into it.
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post by mshita »

Don't you have to tell the system the path to the curl library? How do you do that?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

For as far as i know, you only have to compile php with curl. or include the library if on windows
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post by mshita »

oh okay, thanks. I will try that as soon as I get infront of my computer tomorrow :)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post by mshita »

All I know is that my web hosting company is using Linux and PHP 4 and that they have CURL too.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

curl_exec();
that should work fine than
mshita
Forum Commoner
Posts: 32
Joined: Sat Jul 03, 2004 8:55 pm
Location: Portland, OR
Contact:

Post by mshita »

Cool. Thanks!
Post Reply