/** * This function handles redirecting a user to a given location. * It constructs the $target's absolute path to avoid potential problems. * NOTE: This must be run before any output, or an error will result. */ function redirectTo($target) { $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); header("Location: http://$host$uri/$target"); }