Hello! Happy New Year to everyone!
I’m designing a website system that requires communication between two servers - the best analogy I can give you is PayPal IPN, where:
- Server A takes data from a from and POSTs it to a script on Server B
- Server B script reads the data and POSTs it back to Server A
- Server A verifies that the data is the same as originally sent, sends a ‘status’ message back, and POSTs the data again to the same script on Server B for final processing.
PayPal uses it to verify that data has not been tampered with during transfer. Now I do not need to shuffle the same data back and forth, but I do need to create a similar algorithm.
I have it almost figured out, except for the fact that I send the two scripts on two servers into loops because they are POSTing data to each other back and forth.
What I have figured out so far, and have working now, is the following:
- A script on Server A takes the data and POSTs it to a script on Server B using an HTTP POST constructed in the script itself via fsockopen and fputs (the response is read via fgets)
- A script on Server B successfully receives the POSTed data, processes it, and sends an HTTP Response (200) to the initiating script on Server A. If something is ECHOed in script on Server B, it becomes part of the HTTP Response - this is, I think, how PayPal sends the ‘status’ back.
So far so good…but this is the place where I run into the loop. At this point I need the script on Server B to POST some data (results of the processing) back to the script on Server A. The only way I have thought of is to initiate another HTTP POST through fsockopen and fputs, but this time going in the other direction from Server B back to Server A. The data gets there, but it seems to initiate the original Server A to Server B POST - back and forth several times - the two scripts are just calling each other.
One way to avoid this is for Server B to POST the data to a different script on Server A. However this is not how PayPal IPN works - there data is somehow POSTed back from the PayPal server, along with the HTTP Response, to the same script without starting the script over.
I hope that this makes sense…if not please ask for some clarification. I am wondering, is there a way to POST some data back as part of the HTTP Response?
Thank you!
V