我正在使用 codeigniter 中的rest api
,我想添加api-authentication
,为此,我要发送
access_token
位于邮递员的标头部分,但我想知道如何在.php
文件中获取它。
我只希望尝试在没有access_token
或错误的access_token
的情况下访问api的人不应获得api结果。
在我的controller
中,输入以下代码。如何在rest api上添加身份验证?
if ($access_token!= $_POST['access_token']) {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
} else {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'any text';
}
答案 0 :(得分:-1)
如果要在codeigniter中创建RESTful服务器,请考虑使用https://github.com/chriskacerguis/codeigniter-restserver库。
要在codeigniter中实现API身份验证,请考虑使用https://github.com/ParitoshVaidya/CodeIgniter-JWT-Sample。