I've been e3xperimenting with JSON replies latelly. So as a test i created a small service that autenticates users on another domain. Here's the gist of my initial test:
On domain A, i have a php file that when called with specific GET variables (URI) will return a JSON string to the caller. The idea is i send user and pass and get back a json string with a variable saying wether it was successfully loggedin, user data in case yes and error message case no.
Then i created in domain B a page with javascript and a form. On form submit, the javascript uses XHR (HTMLRequest) to call the page in domain A, retrieve the JSON string, turn it to object and depending on result claim login or not.
This works.
Upon rethinking this i realised for some services this works fine but as login it doesn't since the cliente would be then claiming to the site in domain B 'Hey i've logged in with domain A as user C so you can trust me' - And you really should never trust the cliente.
So i changed things a bit and now the page in domain B submits the user and pass to domain B, and domain B (server-side in PHP) uses file_get_contents to get the JSON string from domain A and decide based on it wether the user is now logged in or not.
This also works and is a lot better in my opinion.
However now i am on phase 3 - even with the server authenticating, i'm still sending the user and pass through URI to domain A. I want to rather send it as POST (or OPTIONS) - as in not in URI - PHP to PHP, preferably as a composed encoded string - like MD5('user:'.$user.':pass:'.$pass)
or something of the kind.
Creating the MD5's string is easy, but how do i POST via PHP then retrieve the result of the POST as string to handle in PHP?