I want to make a desktop application (Delphi) and an online PHP script. Each desktop application sends some unique identifiers to the PHP script and expects an answer (a record of data) from it. The record of data is generated instantly by the PHP script based on the unique identifier received.
I know enough to do the Delphi par开发者_如何学编程t, but I don't know much PHP. Can anybody give me some general lines about how I POST and retrieve data back from the PHP script?
Thanks
EDIT:
I am thinking at something like:
Desktop -> function SendID
PHP -> generate data (and make it persistent) Desktop -> function GetDataBackThe only idea that pops in my mind is to make the PHP script create a file that has the same name as the ID received from the desktop application. Then the desktop app downloads this file and signal the server that the file can be deleted from the server.
Your requirements seem pretty simple... a basic PHP script that solves your problem might look like this:
file: index.php
<?php
$posted_data = $_POST['your_variable_name'];
switch ($posted_data) {
case "UID_APP1":
echo "This is the data being returned for application 1."
break;
case "UID_APP2":
echo "This is the data being returned for application 2."
break;
default:
echo "This is the default data being returned.";
}
To run the PHP script on a server, you need a web server running. Probably, Apache2 will do this job for you since it is one of most commonly used webservers. Depending on your host operating system, there should be a package named apache2 and another one named libapache2-mod-php5. The basic configuration of apache to be able to run php scripts can be found on various websites. (just google for LAMP - "Linux Apache MySQL PHP") I hope this answers your quesion, if not, don't hesitate to ask.
Regards, Paul
In PHP
$delphiAnswer = $_POST['delphiAnswer'];
//DO SOME DATABASE STUFF OR HOWEVER YOU WANTED TO GET THE ANSWER
echo $newAnswerforDelphi;
Fairly simple really, however you need to be more specific about how you want to get answers
Use $_REQUEST, $_POST or $_GET to get your parameters. See W3 Schools site for details. For output, simply echo
what you want to return, in whatever format you want e.g.
<?php
$id = $_REQUEST['id'] ;
$data = /* get the data */
echo json_encode($data) ;
...for JSON.
精彩评论