Question

There are a few things I need help understanding. Long story short: Client has 3rd party application to handle user registration/mailing list/gift cards, it is my job to collect user data, format it in specific JSON object and send to their server. One additional requirement is to pass a username:password header encrypted with base64.

Now, I have a PHP script which is correctly building the JSON object as per their specifications, but I am required to send the POST data to their server, an external web server, along with the mentioned HTTP user authentication header.

So uh, what do I do? I had originally thought to send a PHP header to the client, like so:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

But that's not meant to go to the client. That is meant to go to an external server. Am I supposed to make the client send this header (using javascript)? How can PHP communicate with another server? And finally, how would I send the JSON object to that server, apparently in the same message as the authentication header?

Was it helpful?

Solution

I think cURL is what you need. You can read about it here:
http://www.php.net/manual/en/book.curl.php

With cURL you can easily make HTTP requests including Post, Cookies and lots of other stuff. The JSON object would probably just be sent as one of the Post values, that depends on the API they've given you, though.

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top