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…

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'){


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

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';
   	 		if (!headers_sent()){    
        		header('Location: '.$location);
        	} else {  
		        echo '';
		        echo ''; exit;