1

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?

Radley Sustaire
  • 3,382
  • 9
  • 37
  • 48

1 Answers1

2

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.

Daniel Castro
  • 643
  • 6
  • 16
  • Thanks, I thought curl would have been a separate utility. I've actually used it before in a desktop program to upload files, but I didn't think about using it with PHP. Philip answered the same before you, but I'll give you this one since it's got more information provided by you (Sorry philip!) – Radley Sustaire Dec 29 '11 at 06:20
  • haha no probs dude, yeah Im pretty sure daniel got in there before me actually, although the time says otherwise. I was just extending his anwser which is why it did not contain alot of info. – Philip Dec 29 '11 at 06:44