Php 未经授权的地址栏请求
在cakephp(2.X版)中,我可以对用户进行身份验证,但当用户试图从地址栏访问其尚未访问的网页时,我会遇到问题。 发生的情况是,我被路由到基本索引文件,并出现missingControler错误。 因此,我的路径是..../crm/students,位于用户不应访问的网页上,然后我被定向到/crm/crm/ 我不清楚为什么我没有被重定向到登录页面,而且我被告知使用.htaccess,我不知道这与身份验证有什么关系 我还尝试使用“before filter”重定向用户,但没有成功 我还检查了其他堆栈溢出帖子,但我无法让它正常工作。有人能给我指一下地址栏里的文档吗 处理未经验证的请求Php 未经授权的地址栏请求,php,.htaccess,cakephp,cakephp-2.3,Php,.htaccess,Cakephp,Cakephp 2.3,在cakephp(2.X版)中,我可以对用户进行身份验证,但当用户试图从地址栏访问其尚未访问的网页时,我会遇到问题。 发生的情况是,我被路由到基本索引文件,并出现missingControler错误。 因此,我的路径是..../crm/students,位于用户不应访问的网页上,然后我被定向到/crm/crm/ 我不清楚为什么我没有被重定向到登录页面,而且我被告知使用.htaccess,我不知道这与身份验证有什么关系 我还尝试使用“before filter”重定向用户,但没有成功 我还检查了其
//app controller
公共$components=数组(
)))
}
这与Auth组件的工作方式有关,如果未设置“UnauthorizedDirect”属性,则它似乎会重定向到“/{app directory”,这是您的域-因此,您最终会出现“yourDomain/youDomain” 最简单的修复方法,在AppController add中的Auth组件中
public $componens = array(
//other components
'Auth' => array(
//other properties
'unauthorizedRedirect' => 'url to redirect to' //e.g. '/'
)
);
我尝试了这个,但它没有做任何事情来将某人从未经身份验证的受保护页面公共函数($request,$response){return$this->redirect($this->Auth->logout());}路径中的
crm
是什么?它是路由前缀吗?crm只是cakephp项目的名称,当它应该使用ntrouter::connect('/',array('controller'=>'users','action'=>'login')时,项目将重定向到根目录;这将再次路由到crm/crm/…并重复项目名称,我如何停止此操作,因为这是问题所在?我使用router router::connect(“../”,array('controller'=>'users','action'=>'login')重试了一次;也不走运。我只是不知道如何解决这个问题。抱歉。很好:)查看文档和实际文件中的代码,这实际上应该不是必需的,因为默认值应该能够正确地处理问题-如果我能够找到默认值不能按预期工作的原因,我会让您知道
public function isAuthorized($user) {
// Admin can access every action
// debug($user['role']);
// debug("asdddddddddddddddddddddddddd");
if (isset($user['role']) && $user['role'] === 'admin') {
return true;
}
// return $this->Auth->redirectUrl();
// Default deny
return false;
}
// student controller
public function isAuthorized($user) {
if (isset($user['role']) && $user['role'] === 'manager') {
return true;
}
if (isset($user['role']) && $user['role'] === 'student') {
return true;
}
if (isset($user['role']) && $user['role'] === 'teacher') {
return false;
}
return parent::isAuthorized($user);
`I have the project in a subfolder which could cause the issue Router::connect('/', array('controller' => 'users', 'action' => 'login')); this routes to crm/crm/... again with the` project name repeated and how do i stop this as this is the problem?
public $componens = array(
//other components
'Auth' => array(
//other properties
'unauthorizedRedirect' => 'url to redirect to' //e.g. '/'
)
);