Reputation: 451
I've tried looking for a solution to this issue for a few days now and am getting quite confused.
Aim:
To have a PHP server ("Server A") communicate directly to another PHP server ("Server B") when Server A is visited by user. It then sends a query string to Server B to add in to Server B's database.
Full story:
A visitor will visit Server A and register to their website, as part of their registration Server A will write to Server A's database with all the visitors information. At this point I'd like Server A to load a .php file on Server B and send a query string with it, for example: http://example.com/api/add.php?name=Craig&age=21&key=32r932r9832yr813hr813rh1389ry13r7y31r. Server B, having a PHP file requested from it, will take the variables and run the script on add.php (take the variables and add it to it's database).
Important note: I don't want the client machine to know this, initially I wanted to use JQUERY but realised this sends the request from the client machine and not the server directly.
What is the best way to do this?
Many thanks in advance!
Craig
Upvotes: 0
Views: 717
Reputation: 17487
Learn cURL. Here is an example to get you started:
<?php
$ch = curl_init('http://example.com/api/add.php?name=Craig&age=21&key=32r932r9832yr813hr813rh1389ry13r7y31r');
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
?>
Upvotes: 1