0

Cakephp 3アプリケーションウィジェットにはログイン機能があります。ログイン機能は私のローカルマシン上で完璧に動作します。しかし、プロダクトサーバーでは、ログイン資格情報がcorrcetであると、指定したURLではなく、「\」にリダイレクトされます。私はそれがSessionの問題だと信じています。何らかの理由でセッションがリダイレクションラインで失われたということです。

コード:のAppControllerの

Initilaize方法

public function initialize() 
{ 
    parent::initialize(); 

    $this->loadComponent('RequestHandler'); 
    $this->loadComponent('Flash'); 
    $this->loadComponent('Auth',[ 
      'authenticate'=>[ 
        'Form'=>[ 
          'fields'=>[ 
            'username'=>'username', 
            'password'=>'password' 
          ], 
          'finder' => 'auth', 
        ] 
      ], 
      'loginAction'=>[ 
        'controller'=>'Users', 
        'action'=>'login' 
      ], 
      'loginRedirect' => [ 
        'controller'=> 'Pages', 
        'action'=> 'dashboard' 
      ], 
    ]); 
} 

UserController.php:

class UsersController extends AppController { 


public function initialize() 
{ 
    parent::initialize(); 
} 

public function login() { 
    if ($this->request->is('post')) { 
     $user=$this->Auth->identify();  
     if($user) { 
      $this->Auth->setUser($user); 
      return $this->redirect($this->Auth->redirectUrl()); 
     } else { 
      $this->Flash->error(_('your username or password is incorrect, please try agian'), [ 
       'key' => 'falseSignIn']); 
     } 
    } 
} 
public function logout() { 
    return $this->redirect($this->Auth->logout()); 
} 

}

ここはphpinfo()を使った私のセッション情報です。

enter image description here
+0

loginredirectを定義したappコントローラの初期化機能を表示できますか? – Aparna

+0

私は主な質問に追加しました。どうぞご覧ください – Tanan

答えて

0

URLを返し、次の規則通りである:

1.ReturnsセッションAuth.redirect値から正規化されたURLが存在し、現在のアプリケーションが実行されている同じドメインのためのものである場合。

2.セッション値がなく、config loginRedirectがある場合は、loginRedirect値が返されます。

3.セッションがなく、loginRedirectがない場合は、/が返されます。

は、このコードを試してください:あなたはまた、簡単な方法を使用することができます

public function initialize() 
{ 
    parent::initialize(); 
    $this->loadComponent('Auth', [ 
    'loginAction' => [ 
     'controller' => 'Users', 
     'action' => 'login', 
     'plugin' => 'Users' 
    ], 
    'authError' => 'Did you really think you are allowed to see that?', 
    'authenticate' => [ 
     'Form' => [ 
      'fields' => [ 'username'=>'username', 
          'password'=>'password'] 
     ] 
    ], 
    'storage' => 'Session' 
    ]); 
} 

:あなたは隠されたテキストボックスを作成します$ this-の値を割り当てる必要が

$this->redirect(['action' => 'dashboard']); 
0

を>それにAuth-> redirectUrl()を追加します。フォームからテキストボックスの値を取得し、それを$ this-> redirect()の引数として渡すことができます。