0

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?

4
  • 1
    Firstly please post some code, we are not that mighty to guess everything. Commented Sep 13, 2010 at 13:15
  • @TomaszKowalczyk True. But, can you be mighty and earn 300 points for helping with my question? stackoverflow.com/questions/42172228/… Commented Feb 15, 2017 at 3:46
  • @Lark How's that framework going? is there anything you can help me with? stackoverflow.com/questions/42172228/… Commented Feb 15, 2017 at 3:47
  • @Lark in the system I'm tinkering with, I move all Router validation into a separate class called RouterValidator. I have posted code and UML diagrams here: stackoverflow.com/questions/42172228/… Commented Feb 18, 2017 at 14:30

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I would love to hear any and all thoughts about my problem with creating a routing class. stackoverflow.com/questions/42172228/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.