views:

796

answers:

2

I have a method in users_controller.php of my CakePHP project which is used to remotely log a user in through an AJAX call on a WordPress site. The method works flawlessly when called through Firefox, but when I attempt to call it either via AJAX or directly from the browser in IE8 or Safari, it simply will not log in. The Auth->login() method returns true as if everything is fine, but it does not log in. Any ideas?

function remoteLogin($key)
{
  # this method should only be called via AJAX
  $this->layout = 'ajax';

  $matching_key = '***';

  if($key == $matching_key)
  {
    # auto-login service account
    $data['User']['username'] = '***';
    $data['User']['password'] = $this->Auth->password('***');

    $this->Auth->login($data);
  }
}

Note: I have now confirmed that this method does not work in Opera either. I'm legitimately confused.

A: 

You might want to check your cookies and make sure they are being passed as you expect. Fiddler is helpful to see the http traffic as it goes by to figure out these AJAX issues.

Are www.domain.com and domain.com going to the same place? If so this may be related to a CakePHP / IE issue I ran accross.

Delete any domain level cookies and see if it works.

In IE any domain cookies will take precidence over the subdomain cookies. So if you ever get a cookie going to domain.com and then later go to www.domain.com you can reset your session login, logout all day long but IE will ignore the www.domain.com cookies and continue to use the original domain.com one. I wrote a patch for an old version of Cake that would let you set/force the cookie scope to domain.com even when they are accessing the site as www.domain.com to get around this.

Bryan Waters
A: 

Don't now about IE8, but Safari does block cross-domain ajax, even between "siblings" under the same top domain. E.G. You can't have app.example.com load a div using ajax from helppages.example.com. Forget cookies, I am talking just plain html loaded using ajax.

Martin Westin