Question

Is there a way I can have a plugin redirect the whole page when it is getting called through an AJAX request?

Here is the code I am using to redirect non-authenticated users to the login page.

public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
    if ($request->getControllerName() != 'authentication') {
        if (!Zend_Auth::getInstance()->hasIdentity()) {
            $request->setControllerName('authentication');
            $request->setActionName('login');
            return;
        }
    }
}

This works for normal requests but I want it to redirect users to the login page when they make AJAX requests after they are logged out. Using what I have now it loads the HTML for the login page inside the HTML element that is designated to house the result of the AJAX request.

How can I have it redirect the browser to the login page instead of just loading the login page inside the current page?

Was it helpful?

Solution

Well if i'm understanding you correctly. drew010 is correct, the ajax call is a different http request not the one the user is actually seeing and interacting with. So without using javascript php can't leap from one http connection to a different connection and execute a redirect. PHP isn't an 'active' language it's a 'reactive' language. meaning it doesn't do anything until the page is loading/refreshing.

But if you want to handle the redirect via ajax or not ajax it's your initiator to the redirect. since that's whats actually making the call to trigger the whole process your wanting anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top