Vla*_*ado 5 authentication jquery digest
据我所知,我有以下功能:
如果用户转到另一个页面,它将收到“401 访问被拒绝”,因为该请求中没有身份验证标头。这就是问题所在。
小智 1
我使用基本的 HTTP 身份验证来使用 joomla 组件中的 REST Web 服务,并且我的用户无需输入任何内容(只需登录 joomla 一次)。我只是获取已经登录的用户,然后使用 CURL 将其发送到我的网络服务
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//$username and $pass are the vars that will be used for authentication you can get them from your session or a cookie or in my case i got them from joomla JFactory::getUser()->username and JFactory::getUser()->password
curl_setopt($ch, CURLOPT_USERPWD, JFactory::getUser()->username.':'.JFactory::getUser()->password);
//here comes the important thing
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response=curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
另一方面,您只需检查$_SERVER['PHP_AUTH_USER']
数据库$_SERVER['PHP_AUTH_PW']
即可完成
if (!isset($_SERVER['PHP_AUTH_USER'])||$_SERVER['PHP_AUTH_USER']==''||!isset($_SERVER['PHP_AUTH_PW'])||$_SERVER['PHP_AUTH_PW']=='') {
header('WWW-Authenticate: Basic realm="Something"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must be a valid user to access this contents';
exit;
} else {
// go to your database check they are valid and return whatever you want to return
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1888 次 |
最近记录: |