/** * Correctly redirects the user to the specified webpage using the Location Header. * * @access public * @var string URL to Send User to * @var int [OPTIONAL] 3xx Code to use (301,302,303,305 or 307) [Default: 307] * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3 * @return bool */ public function location($location,$code = 307,$replace = true) { $a = explode(":",$_SERVER['SCRIPT_URI']); $prefix = $a[0]; $uri = $_SERVER['HTTP_HOST']; // if ($code == 300) { header("HTTP/1.1 300 Multiple Choices"); } // if ($code == 301) { header("HTTP/1.1 301 Moved Permanently"); } // if ($code == 302) { header("HTTP/1.1 302 Found"); } // if ($code == 303) { header("HTTP/1.1 303 See Other"); } // if ($code == 305) { header("HTTP/1.1 305 Use Proxy"); } // if ($code == 307) { header("HTTP/1.1 307 Temporary Redirect"); } /* if ($code == 300 && is_array($location)) { foreach($location as $v) { $this->location($v,300,false); } return TRUE; } */ if (substr($location,0,1) == '/') { header("Location: $prefix://$uri$location",$replace,$code); } else { if (!strchr($location,":")) { $b = explode("/",$_SERVER['REQUEST_URI']); $c = count($b)-1; $d = ""; foreach($b as $k => $v) { if ($k == $c) { $d .= $location; } else { $d .= "$v/"; } } $location = $d; header("Location: $prefix://$uri$location",$replace,$code); } else { header("Location: $location",$replace,$code); } } }