Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Redirects user to destination, which can be
- * a URL or a relative path on the local host.
- *
- * Because this function outputs an HTTP header, it
- * must be called before caller outputs any HTML.
- */
- function redirect($destination)
- {
- // handle URL
- if (preg_match("/^https?:\/\//", $destination))
- {
- header("Location: " . $destination);
- }
- // handle absolute path
- else if (preg_match("/^\//", $destination))
- {
- $protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http";
- $host = $_SERVER["HTTP_HOST"];
- header("Location: $protocol://$host$destination");
- }
- // handle relative path
- else
- {
- // adapted from http://www.php.net/header
- $protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http";
- $host = $_SERVER["HTTP_HOST"];
- $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
- header("Location: $protocol://$host$path/$destination");
- }
- // exit immediately since we're redirecting anyway
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement