No announcement yet.

[PHP] Trouble redirecting on error

  • Filter
  • Time
  • Show
Clear All
new posts

  • [PHP] Trouble redirecting on error

    I wish to redirect my visitors to a certain page if my require statement fails to load the script I have it loading. I've used one I found and edited for an error checked but then upon using the redirect code it wouldn't work.

    			function redirectOn_error() {
    				$isError = false;
    				if ($error = error_get_last()) {
    					switch($error['type']) {
    						case E_COMPILE_ERROR:
    							$isError = true;
    				if ($isError) {
    I have the switch case for future ability to add redirects for certain errors or do certain things upon certain errors. Any suggestions you have are appreciated. Also some redirect code would be appreciated.

  • #2
    AFAIK require will not let you do a redirect because it immediately kills script execution.

    From the PHP docs:

    require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.


    • #3
      I am lost on the compile statement, if they want to show an error on PHP compile, which only happens when the server has restarted or the php.ini has changed basically, the php code is useless, it will never run in the first place.
      Have a Script or Snippet you want to share?

      WWW Standards: HTML 4.01,
      HTML 5, CSS2.1, CSS3, XHTML 1.0
      PHP Standards: PHP Standards