1

Convoluted issue but i'll try my best to summarize.

I have a login setup using Cakephp Auth Component, which depending on the role of the user, will redirect the user to the appropriate page. It seems to work fine on Chrome / FF / IE 10 on my local development WAMP setup. But it seems to fail with IE after I've uploaded the site to Bluehost.com.

The problem is when logging into my website on bluehost via IE10, i keep getting redirected back to the login page after logging in. The redirect seems to work on any other browser. Strangely it works on IE10 on local dev environement.

USING CAKEPHP 2.4.5

Local dev: (post login redirect seems to work fine on all browsers)

Wamp 2.4 Apache 2.4.4 PHP 5.4.12 MYSQL 5.6.12

Bluehost: (post login redirect does not seem to work on IE10, redirects back to login page!)

PHP 5.4 Apache ???

Here is the cut down version of my AppController showing the Auth declarations.

class AppController extends Controller {

    public $components = array(
        'DebugKit.Toolbar',
        'Session',
        'Auth'=>array(
            'loginAction'=>array('controller'=>'users', 'action'=>'login'),
            'logoutRedirect'=>array('controller'=>'users', 'action'=>'loggedout'), 
            'authError'=>'You cannot access that page', //Error message whenever someone access a page without auth
            'authorize'=>array('Controller') //Where in our application that authorization will occur
        )
    );

    ////Determines what logged in users have access to
    public function isAuthorized($user) {

        if($user['role'] == 'admin') {
            switch ($this->name) {
                case 'Home':
                    return true;
                    break;              
                case 'BillingCenters':     
                    return true;
                    break;
                case 'Merchants':     
                    return true;
                    break;
            }
        }
        if($user['role'] == 'merchant') {
            switch ($this->name) {
                case 'MCP':
                    return true;
                    break;
                case 'Users':
                    switch ($this->action){
                        case 'logout':
                            return true;
                    }
                    return false;

            }
        }

        die('isAuthorized in AppController denies access to this controller called: ' .  $this->name);
    }

    //Determines what non logged in users have access to
    public function beforeFilter() {
        //Logic placed here will run before the action is run
        parent::beforeFilter();
        $this->Auth->allow('loggedout', 'login');

    }
}

Here is the code in my UsersController that pertains to the login. I removed a chunk of SQL database lookup code tat populates the User Role into a session variable to make it more readable. What matters is the end bit that redirects the user based on his role.

public function login() {

    $this->layout = 'loginlogout';


    if ($this->request->is('post')) {
        if ($this->Auth->login()) {

            /* ---- removed chunk of code that determines Auth.User.role value for Session... for readability, -- */

            if ($this->Session->read('Auth.User.role') == 'admin') {
                $this->redirect(array('controller' => 'home', 'action' => 'index'));

            }
            if ($this->Session->read('Auth.User.role') == 'merchant') {
                $this->redirect(array('controller' => 'MCP', 'action' => 'snapshot'));

            }
            die('Unable to determine user role for redirection');

        } else {
            $this->Session->setFlash('Your username/password combination was incorrect');
        }
    }

}

And below I have attached screenshots of the different browser network traces when after clicking onto the login button. After logging in i am expecting to be redirected to the "MCP/Snapshot". All screenshots are taken when logging into my website on the live server (Bluehost).

CHROME (Login and post login redirect works!) enter image description here

Firefox (Login and post login redirect works!) enter image description here

IE10 INTERNET EXPLORER 10 - AFTER LOGGING IN, FAILS TO Load MCP SNAPSHOT PAGE/ACTION and brings user back to Login page again!! enter image description here

It seems to work when logging into my local development environment (no screenshots provided). Give me a clue someone why this is not working for IE10 on Bluehost? I'm not sure i understand the HTTP return codes 302 either!

aDvo
  • 894
  • 4
  • 15
  • 43

1 Answers1

2

I've come to realize through some tests that it seems Internet Explorer / IE was losing my session information each time I changed a page, whether it as a manual url entry into the URL bar, or a redirect triggered by a redirect command of Cakephp.

I've found that this solution of adding session_start() at the webroot/index.php mysteriously helps this problem to go away. I'm not sure how to explain it and i hope it does not create additional bugs simply because i do not fully understand the implications on cakephp of inserting this line of code.

https://stackoverflow.com/a/16720810/3189873

I've found that other solutions to do with adjusting values for User Agent and for Security Level in core.php, do not really seem to help, although their problems and symptoms seem similar to mine.

http://derickng.com/posts/36-cakephp-losing-or-missing-session

CakePHP Cookie/Session problems

Community
  • 1
  • 1
aDvo
  • 894
  • 4
  • 15
  • 43