Jump to content

How do I communicate between 2 servers?


mattd8752

Recommended Posts

I am creating a stats suite.

 

I don't have access to run Command Line scripts so I can't rely on a socket server.

 

I want to have the user's server message mine a few details (the page loaded, a code to verify that it is the real server not someone trying to screw up the records, the users IP, and the refferer).

 

I need this to be sent from a script on their server to my server to be added to the logs.

Link to comment
https://forums.phpfreaks.com/topic/47052-how-do-i-communicate-between-2-servers/
Share on other sites

Guest prozente

With PHP you'd make a connection using sockets to the other server on port 80, this is to the webserver

Then you'd send your packet, if you were using GET it would look something like this

$http_request  = "GET /script.php?variable1=123&foo=bar HTTP/1.0\r\n";
$http_request .= "Host: example.com\r\n";
$http_request .= "User-Agent: bot\r\n\r\n";

 

See the PHP manual for information on using sockets, I don't want to do it all for you. The examples on the page are well enough.

 

http://us2.php.net/manual/en/ref.sockets.php

 

then on your script.php you'd check $_SERVER['REMOTE_ADDR'] to make sure it was your other servers IP address and not just someone trying to send fake information. This is far better than using any type of password since your servers IP is static.

 

once you check the IP Address and it is correct you would use $_GET['variable1'] and $_GET['foo'] to access the data

 

When crafting the packet use urlencode on data you plan to put in a variable

 

This should be enough to get you started.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.