开发者

Authentication using JSON and PHP

Can anyone kindly tell me how to use JSON base Authentication using/in PHP?

I got some helping code (as given below), but can not understand that how to use it.

 url = http://testerws.heroku.com/   
 POST url + 'user_session.json',{:username => "admin",:password => "admin"}, :accept => 'application/json'

I am not sure whether this code is correct (with respect to syntax) o开发者_如何学Cr not. And I can not understand how to use it in combination with PHP.

So kindly help me to solve this, I am in great need of it.


You can use curl of php to post the json data.

$json = json_encode($data);
$http_post_data = array("data" => $json);

$url = 'http://testerws.heroku.com/test.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $http_post_data);

$result = curl_exec($ch);
curl_close($ch);

Then test.php will get the data which you post. You can do authentication your self and return to the calling script.

But the authentication is not that easy for a security system.
FYR.
http://blog.evernote.com/tech/2011/05/17/architectural-digest/
and read the comment.


What is the context of the authentification? If it's a webapplication you could probably fill in a form, post the data as JSON using JQuery and decoding the JSON on the PHP side and check the validation. Be sure to encrypt the information you send from the browser though. Username and password as clear text is not secure at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜