views:

39

answers:

2

Hi, I am using CakePHP v1.2 for my web application hosted here: http://lol-land.in

The application was working fine till Yesterday, but it suddenly started to get stuck in some redirection loops. What makes it weirder is the fact that the problem is with just one controller: posts. And even in that most of the functions are working. But http://lol-land.in/posts is redirecting to lol-land.in/posts/view/133 which is in turn redirecting to itself.

Actually 110 of the 117 posts of the form /posts/view/ are stuck in this 302 redirection.

Can anyone please tell me what could have caused this?

[CakePHP 1.3 and PHP5]

Edit: Adding View Logic

function view($id = null) {
$this->log("View Logic Entry", LOG_DEBUG);
// These Log entires are missing 

$this->layout = 'postview';
if (!$id) {
    $this->Session->setFlash(__('Invalid Post.', true));
    $this->log("Redirect due to missing id", LOG_DEBUG);
    $this->redirect(array('action'=>'index'));
}
$log = $this->Session->read('Auth.User');
$logid = $log['id'];

$temp = $this->Post->read(null, $id);

$ratings = $temp['Rating'];

$this->set(compact('up', 'down', 'userrated', 'userrateid'));

$coms = $temp['Comment'];
$comuser = array();
for ($i=0; $i<count($coms); $i++) {
    $comuser[$i] = $coms[$i]['user_id'];
}
$comuser = $this->Post->User->find('list', array( 'fields'=>array('User.id', 'User.username'),
                      'conditions'=>array("User.id" => $comuser)
                      ));
$this->set(compact('comuser'));

$this->pageTitle = $temp['Post']['title'];
$this->set('post', $temp);
$alltypes = $this->Post->Type->find('list', array('fields'=> array('Type.id', 'Type.typename')));
$selectedtab = -1;
$this->set(compact('alltypes', 'selectedtab' ));


//Calling updateFBStats
// Removed because unnecessary.

}

+1  A: 

Chances are you are either 1) using circular references with the Auth component OR 2) the function in your controller is redirecting do to something within the method. Can you show the code of posts_controller.php function view() ?

cdburgess
The 'view' action was calling some 3-4 other actions, and somewhere I had used == to compare values and not ===. So null == 0 gave 'true' which resulted in redirection back to view. And hence the issue.Basically, very bad programming on my side.But, Thanks for the help :)
Mayank
A: 

Hello Mayank.

The application was working fine till Yesterday, but it suddenly started to get stuck in some redirection loops.

To state the obvious: What have you changed in your codebase since the last working status. When you identified the changes find out how to implement these correctly or come up with a more specialized question here on SO.

If you introduced Auth lately, which is a good guess (cdburgess already mentioned it), you must make sure that the places you redirect to, are allowed to unauthenticated users, e.g. like

$this->Auth->allow('index');

in your beforeFilter() method of the posts controller and don't forget to call

parent::beforeFilter();

if you perform relevant settings there.

Kind regards, Benjamin.

P.S.: Btw i cannot confirm having troubles with your site, but I highly doubt you would have rolled out with this issue.

benjamin