How can a PHP script on Server B return a specific value to Server A after processing form data?
To return a specific value from a PHP script on Server B to Server A after processing form data, you can use cURL to make a POST request from Server A to Server B. Server B can process the form data and then return the specific value as a response. Server A can then retrieve this value from the response.
// PHP script on Server A
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://serverB.com/process_data.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['form_data' => $_POST['form_data']]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response !== false) {
// Process the specific value returned from Server B
echo $response;
} else {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
Related Questions
- What are common pitfalls to avoid when working with arrays and file handling in PHP?
- How can the PHP code be optimized for better readability and maintainability, especially in terms of programming style and structure?
- What are the potential drawbacks of not being able to use active mode in FTP connections with PHP?