cakephp:$this->Auth->user()登录在生产服务器上不工作?

cakephp:$this->Auth->user()登录在生产服务器上不工作?,cakephp,login,components,authentication,production-environment,Cakephp,Login,Components,Authentication,Production Environment,生产服务器上的Auth组件有问题。当我输入用户名和密码并单击登录时,除了密码文本框会自动清除外,什么也不会发生。我收到“我登录失败了”。我不知道为什么它根本不进入“if$this->Auth->user” 早些时候,在我的开发服务器上,这个Auth组件工作得非常好。我可以登录一个用户,一旦用户登录,他/她的孩子的报告卡pdf文件就会显示出来 有人能指出我犯了什么错误吗?多谢各位 merry_parents_controller.php class MerryParentsController e

生产服务器上的Auth组件有问题。当我输入用户名和密码并单击登录时,除了密码文本框会自动清除外,什么也不会发生。我收到“我登录失败了”。我不知道为什么它根本不进入“if$this->Auth->user”

早些时候,在我的开发服务器上,这个Auth组件工作得非常好。我可以登录一个用户,一旦用户登录,他/她的孩子的报告卡pdf文件就会显示出来

有人能指出我犯了什么错误吗?多谢各位

merry_parents_controller.php

class MerryParentsController extends AppController{

var $name='MerryParents';
function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->autoRedirect=false;
                        //$this->redirect($this->Auth->redirect());
}

function login(){
    echo "i'm in login";
    if ($this->Auth->user()){
        debug($this->Auth->user());
        $this->data=$this->Auth->user();
        if (!empty($this->data)){

                    $student_info=$this->MerryParent->Student->getStudents($this->data['MerryParent']['id']);
                    $this->set('student_info',$student_info);
                    print_r($student_info); 
                    $this->redirect(array('controller'=>'aptitudes','action'=>'viewpdf',$student_info['Student']['id']));
                    //$this->render('/aptitudes/viewpdf');  
            }
        else{
            echo 'Auth user has not been set';
            }

    }
    else
        echo "Failure";

}
}
class AppController extends Controller {
var $components=array('Auth','Session','Cookie','Email','Security','RequestHandler','Cookie');
var $helpers = array('Html','Form','Ajax','Javascript','Session');

function beforeFilter(){
  if (isset($this->Auth)){
        $this->Auth->userModel='MerryParent';
        $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
                    /*var_dump($this->data);
                    debug($this->Auth->user);*/
        $this->Auth->allow('*');
        $this->Auth->loginRedirect=array('controller'=>'aptitudes','action'=>'viewpdf');
        $this->Auth->logoutRedirect=array('controller'=>'merry_parents','action'=>'register');
        $this->Auth->authorize='controller';
      }
   else
        $this->Session->setFlash('Auth has not been set');  

}

function isAuthorized(){
    return true;
}
login.ctp

<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('MerryParent.username',array('label'=>'Name'));
echo $this->Form->input('MerryParent.password', array('value'=>''));
echo $this->Form->end('Login');
?>
试试这个:

<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('username',array('label'=>'Name'));
echo $this->Form->input('password', array('value'=>''));
echo $this->Form->end('Login');
?>
试试这个:

<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('username',array('label'=>'Name'));
echo $this->Form->input('password', array('value'=>''));
echo $this->Form->end('Login');
?>

有两个问题。在我按照CodeParadox的答案修改了登录函数之后,直到我修改了core.php的Security.salt和Security.cipherSeed,它才开始工作。我刚刚从我的开发服务器的core.php复制了salt和cipherSeed的值,它成功了!:


谢谢。

有两个问题。在我按照CodeParadox的答案修改了登录函数之后,直到我修改了core.php的Security.salt和Security.cipherSeed,它才开始工作。我刚刚从我的开发服务器的core.php复制了salt和cipherSeed的值,它成功了!:


谢谢。

删除控制器最后一行或其他使用php文件(如配置、组件和帮助程序)中的额外空间


删除控制器最后一行或其他使用php文件(如配置、组件和帮助程序)中的额外空间


您的Author.authorize Controller应为大写字母,如下所示:

$this->Auth->authorize='Controller';

您的Author.authorize Controller应为大写字母,如下所示:

$this->Auth->authorize='Controller';

我尝试了你的解决方案,结果与上面相同。什么也没发生。是的,它现在起作用了。但是有两个问题:一是登录函数中的代码。core.php中的Security.salt&Security.cipherSeed。我尝试了您的解决方案,结果与上面相同。什么也没发生。是的,它现在起作用了。但是有两个问题:一是登录函数中的代码。core.php中的2Security.salt&Security.cipherSeed。您的登录函数确实有问题。通过执行$this->data=$this->Auth->user,您正在清除传递到此函数的数据。只有在您已登录的情况下,此操作才有效。您应该首先通过将此->数据传递给Auth Login函数来登录…您的登录函数确实有问题。通过执行$this->data=$this->Auth->user,您正在清除传递到此函数的数据。只有在您已登录的情况下,此操作才有效。您应该首先通过将此->数据传递给Auth Login函数来登录。。。