X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=http.php;h=e325fc1747e41a4f7214f640a2edfad144ef49e1;hb=73490300ca9dea6fc3c6d3a474ab49796fd58438;hp=437ec74e013d5db8cbe307deefac89702ddb5459;hpb=22d5fb7ab7d4ee86bd59e194387dca268bd577a1;p=wfpl.git diff --git a/http.php b/http.php index 437ec74..e325fc1 100644 --- a/http.php +++ b/http.php @@ -19,8 +19,8 @@ # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# return our best guess at the url used to access this page -function this_url() { +# return our best guess at the url used to access this page, without the path or query string +function this_url_sans_path() { list($protocol, $version) = explode('/', $_SERVER['SERVER_PROTOCOL']); $url = strtolower($protocol); @@ -42,13 +42,41 @@ function this_url() { } } + return $url; +} + +# return our best guess at the url used to access this page +function this_url() { + $url = this_url_sans_path(); + $url .= $_SERVER['REQUEST_URI']; return $url; } +# sends an HTTP redirect +# +# $url can be: +# 1) a full URL +# 2) an absolute path +# 3) a filename (you can pass a directory/file.html and such, but "../" prefix is not supported yet) function redirect($url, $status = '302 Moved Temporarily', $message = '') { - header("HTTP/1.1 $status"); + if(!strpos($url, ':')) { + while(substr($url, 0, 2) == './') { + $url = substr($url, 2); + } + if(substr($url, 0, 1) == '/') { + $url = this_url_sans_path() . $url; + } else { + $url = ereg_replace('/[^/]*$', "/$url", this_url()); + } + } + + if(function_exists('session_save_messages')) { + session_save_messages(); + } + + header("HTTP/1.0 $status"); header("Location: $url"); echo($message); exit();