The redirect class is designed to handle your error pages and your page redirects. The basic redirect function looks for numeric server codes and sends you to the proper place. (See case '404' in the code below). The primary use of the redirect class is to send users to other places without causing headers already sent errors.

It can be called like this…
Redirect::to('account.php');

I also like to use it in if statements. It's a great way to send people away who aren't the super admin. Like this will redirect any user that doesn't have a user id of 1.

if($user->data()->id !='1'){
  Redirect::to('account.php');
}

Redirect.php

If you copy and paste this code, please get rid of the spaces or @ symbols before the opening php tag.


<@?php
class Redirect {
	public static function to($location = null){
		if ($location) {
			if (is_numeric($location)) {
				switch ($location) {
					case '404':
						header('HTTP/1.0 404 Not found');
						include 'includes/errors/404.php';
						break;
				}
			}
   	 		if (!headers_sent()){    
        		header('Location: '.$location);
        		exit();
        	} else {  
		        echo '';
		        echo ''; exit;
		   	 	}
		}	
	}
	
}