Page 1 of 1
PHP and sockets
Posted: Thu Oct 14, 2004 1:10 am
by yagnbda
hi,
I have a problem and want help about it.
I want to execute a php script by a sockt application(built in c++), this socket application passes socket information to the php code which stores this information into MYSQL database.
I want to know
1-) how an application(not web application) can call php script located on remote location.
2-) how php provide interface so that another application(not web application) can pass parameter to php function.
I hope you people can help me.
thanks
Posted: Thu Oct 14, 2004 3:16 am
by timvw
the easiest solution:
change design from c++ -> php -> mysql to c++ -> mysql
you could also use a binary like wget/curl and then call that from c++ with the correct url (and post/get data).
Posted: Thu Oct 14, 2004 5:48 am
by yagnbda
No, i cant do this because i am to store my database remotly. i.e i will have to connect webserver on remote system and execute php located on that server. so i want to interact c++ and php
Posted: Thu Oct 14, 2004 5:57 am
by kettle_drum
Simply have the C++ script open a connection to the php script on the remote server - just like a browser does - and then pass the info along to it. You can use GET or POST and add a user/pass as well.
Posted: Thu Oct 14, 2004 6:10 am
by yagnbda
how to interact with php through c++, is there any specific way of interaction?
Posted: Thu Oct 14, 2004 6:21 am
by timvw
i'll quote myself :p
timvw wrote:you could also use a binary like wget/curl and then call that from c++ with the correct url (and post/get data).
Posted: Thu Oct 14, 2004 6:29 am
by kettle_drum
Or you just create a socket in C++.
Posted: Thu Oct 14, 2004 6:36 am
by yagnbda
i have a socket already created in c++,
1) is there any way i can execute abc.php file on a remote computer through my c++ application
2) is there any way that a php function can get parameters from c++ application, if so then how c++ will pass parameter to php functions.
Posted: Thu Oct 14, 2004 7:12 am
by kettle_drum
The php file must be run by the php interupter which is generally used with a web server. To run the file you have to mimic a web browser - so you connect to the server with the php file on whatever port the web server is running on and pass any varaibles you want to give the script through either POST or GET in the http protocol. The php script can then get this variables by:
Code: Select all
$_GET['some_var'];
$_POST['some_var'];
And you can therefor pass these variables around the php script as you wish.
Posted: Thu Oct 14, 2004 9:50 am
by timvw
for the lazy, unwilling to code a http1 implementation
Code: Select all
int main(void)
{
system("curl -d 'uid=myid&pwd=mypass&lang=en' https://kuleuven.ac.be/weblogin.cgi");
return 0;
}