-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirect.php
46 lines (40 loc) · 1.08 KB
/
Redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// A redirect class to eliminate having to use header('Example.php').
class Redirect
{
// The class takes a location specified in an external class as
// Redirect::redirectTo(Example)
// this adds more functionality as using this class the user can
// be directed an error template I.e. 404 - Or any other
// error template we would require (Could add functionality to
// display custom messages dependant on the error).
public static function redirectTo($location = null)
{
if($location)
{
if(is_numeric($location))
{
switch($location)
{
// In case of a 404 error.
case 404:
header('HTTP/1.0 404 Not Found');
include 'PHP/includes/errors/404.php';
exit();
break;
// In case of a 403 error.
case 403:
header('HTTP/1.0 403 Forbidden');
include 'PHP/includes/errors/403.php';
exit();
break;
}
}
// Used in the code to redirect to a specified location
// I.e. Redirect::redirectTo();
header('Location: ' . $location);
exit();
}
}
}
?>