views:

98

answers:

1

I have an odd issue that I can not for the life of me figure out. First of all I have developed a PHP MVC framework from scratch. The problem I am having is that I am getting a header redirect execution after an exit() call.

Here is a high level view of the routing process:

  1. REQUEST_URI is stripped apart and the requested controller, method, and any arguments are set to variables to be used later in the script.
  2. The router.php checks to make sure if the requested controller actually exists, if it doesn't then it returns false but if everything checks out then it returns true
  3. If it returns true, it executes the requested controller, method, and any arguments.
  4. If it returns false then the router will send a redirect to a custom 404 page. This uses PHP's header() function and there is an exit() after the header("Location: *");

Step 4 is where the problem occurs. The requested controller exists so it executed and the requested view exists so it loads everything correctly but then it executes the redirect even though an exit() is called after successfully loading the view.

Is there any reason why the router would continue on and fire the redirect?

A: 

I'm not going to guess (as per @Tomasz :), but even if you exit() the browser is going to respect any http headers it gets, including a Location.

In fact in something similar I do, on any errors I send a redirect header and then do an exit to make sure execution doesn't continue in the controller after the redirect.

Fanis