How to get a specific response (data record) from a PHP script based on the parameters sent to this script?

I want to make a desktop application (Delphi) and an online PHP script. Each desktop application sends unique identifiers to a PHP script and expects a response from it (data records). A data record is instantly generated by a PHP script based on the received unique identifier.

I know enough to make part of Delphi, but I do not know much PHP. Can someone give me some general lines on how I send POST and retrieve data from a PHP script?

thanks


EDIT:

I am thinking of something like:

Desktop -> SendID Function
PHP -> generate data (and make it persistent)
Desktop -> GetDataBack Function

The only idea that appears in my head is to make the PHP script create a file with the same name as the identifier received from the desktop application. The desktop application then downloads this file and signals to the server that the file can be deleted from the server.

0
source share
3 answers

Your requirements seem pretty simple ... the 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 a PHP script on a server, you need a web server. Apache2 will probably do the job for you as it is one of the most commonly used web servers. Depending on your host operating system, there should be a package named apache2 and another named libapache2-mod-php5. The basic apache configuration for running php scripts can be found on different sites. (just Google for LAMP - β€œLinux Apache MySQL PHP”) Hope this answers your question, if not, feel free to ask.

Regards, Paul

+3
source

In php

 $delphiAnswer = $_POST['delphiAnswer']; //DO SOME DATABASE STUFF OR HOWEVER YOU WANTED TO GET THE ANSWER echo $newAnswerforDelphi; 

Simple enough, but you need to know more specifically how you want answers

+1
source

Use $ _REQUEST, $ _POST or $ _GET to get your parameters. See W3 Schools for more details. To output simply echo what you want to return, in any format you want, for example.

 <?php $id = $_REQUEST['id'] ; $data = /* get the data */ echo json_encode($data) ; 

... for JSON.

+1
source

Source: https://habr.com/ru/post/1340436/


All Articles