Php and C++ ?
Hi,
I would like to know if there is any kind of way to execute a php or perl script on a remote machine in a c++ program.
For example, in my c++ game, execute a php script : http://www.foosite.com/foo.php
Pass it some parameters and receive a return value of the script...
That would be great because I would be allowed to modify the php code and not modify the c++ code of my game so I would be more flexible. (It''s to comunicate with a mysql database)
I know that I can use a mysql c++ librairie. Is there a sort of php librairie for c++ to execute php scripts ?
Thomas DecroyèreCheck out my blog at: http://thomas.decroyere.be
The only way I can think of is to make a HTTP connection to the script which is either a perl/php CGI script of a php script with php running as a webserver module.
What you have to do is write your script and stick it where somewhere on your site and then in to C++ program make a connection to the IP of the webserver on port 80 (or what ever you are using - so other number might be a bit better if you didn't want people to find too easily) its then a matter of sending a http get header which is quite simple really but I can't remember off hand but its something like this
GET /scripts/script.php HTTP/1.0
You whould have to pass your parameters either as a query string format which I think all you have to do is
GET /scripts/script.php?param1=val¶m2=val¶m3=val HTTP/1.0
but I could be wrong, or do it in post mode where I think you do something like after the GET line send line like this
param1=val
param2=val
param3=val
but I'm really not too sure.
Once you've done all read the output from the php script then close you connection.
===
There is another solution, write you script as a server/daemon which is running all the time on the server waiting for a connect on a port of your choice using you own protocol. Its not too hard to do but I haven't tried to do it in php so I don't know if its possible, works fine in C or perl though.
Any way good luck, I'll watch this thread for a bit in case you have any questions.
Edited by - xstreme2000 on August 22, 2001 10:40:42 AM
What you have to do is write your script and stick it where somewhere on your site and then in to C++ program make a connection to the IP of the webserver on port 80 (or what ever you are using - so other number might be a bit better if you didn't want people to find too easily) its then a matter of sending a http get header which is quite simple really but I can't remember off hand but its something like this
GET /scripts/script.php HTTP/1.0
You whould have to pass your parameters either as a query string format which I think all you have to do is
GET /scripts/script.php?param1=val¶m2=val¶m3=val HTTP/1.0
but I could be wrong, or do it in post mode where I think you do something like after the GET line send line like this
param1=val
param2=val
param3=val
but I'm really not too sure.
Once you've done all read the output from the php script then close you connection.
===
There is another solution, write you script as a server/daemon which is running all the time on the server waiting for a connect on a port of your choice using you own protocol. Its not too hard to do but I haven't tried to do it in php so I don't know if its possible, works fine in C or perl though.
Any way good luck, I'll watch this thread for a bit in case you have any questions.
Edited by - xstreme2000 on August 22, 2001 10:40:42 AM
Well if you want it to execute the script
by accessing http://www.somesite.com/foo.php
the you could just open a connection to
www.somesite.com port 80
and set a http request..
if i remember correctly it looks something like this
"GET HTTP://www.somesite.com/foo.php\n\n"
but you can check the standard
but this will give you awful performance.
by accessing http://www.somesite.com/foo.php
the you could just open a connection to
www.somesite.com port 80
and set a http request..
if i remember correctly it looks something like this
"GET HTTP://www.somesite.com/foo.php\n\n"
but you can check the standard
but this will give you awful performance.
Jonas Meyer Rasmussenmeyer@diku.dk
Thank you very much for your replies.
I will try that
I will try that
Thomas DecroyèreCheck out my blog at: http://thomas.decroyere.be
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement