diff options
author | Christian Helbling | 2011-09-08 09:53:28 +0000 |
---|---|---|
committer | Christian Helbling | 2011-09-08 09:53:28 +0000 |
commit | 086b8bd74b89931143340929cc349308411499a3 (patch) | |
tree | 8383dcc2717d96af16fc4b03091de6f979a5d86b /it_url.class | |
parent | bb113f3bc0d451fa33af8b4ea9635d08e6df91a0 (diff) | |
download | itools-086b8bd74b89931143340929cc349308411499a3.tar.gz itools-086b8bd74b89931143340929cc349308411499a3.tar.bz2 itools-086b8bd74b89931143340929cc349308411499a3.zip |
add support for permanent redirect, change default/temporary redirect from 302 to 303 which is what is usually meant and is the (incorrect) behaviour of most clients on a 302
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/it_url.class b/it_url.class index ff189c1..56aa182 100644 --- a/it_url.class +++ b/it_url.class @@ -677,18 +677,18 @@ function absolute($url=null) /** * Craft a valid redirect URL, send Location: header and terminate execution - * @param $url Optional URL ( foo.html, /foo.html, //host/bar.html, http://host/bar.html ), default self + * @param $url Optional URL ( foo.html, /foo.html, //host/bar.html, http://host/bar.html ), default self + * @param $type Type of redirect, "temporary" or "permanent", default temporary * @return This method never returns. */ -function redirect($url = null) +function redirect($url = null, $type = "temporary") { $url = preg_replace("/[\r\n].*/", '', it_url::absolute($url)); # Security: cut after CR/LF - + $code = substr($type, 0, 4) == "perm" ? 301 : 303; # NOTE: HTTP 303 is called "See Other", rather than Temporary (which would be HTTP 307), but is the behaviour one usually wants for temporary redirects if (EDC('noredir')) - echo "<a href='" . htmlspecialchars($url) . "'>" . htmlspecialchars($url) . "</a><br />" . it_debug::backtrace(); + echo "<a href='" . htmlspecialchars($url) . "'>" . htmlspecialchars($url) . "</a> (HTTP/1.1 $code, $type redirect)<br />" . it_debug::backtrace(); else - header('Location: ' . it_untaint($url, TC_SELF)); - + header('Location: ' . it_untaint($url, TC_SELF), true, $code); exit; } |