X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=http.php;h=2907410ffe4b703e321e7af4573f4be2c9a8884e;hp=c38f97d8ee2e64b03203a02b13298d83f9de3a8e;hb=HEAD;hpb=3bec0ef771d741361c6c4c4c1ff069398f6e37a0 diff --git a/http.php b/http.php index c38f97d..2907410 100644 --- a/http.php +++ b/http.php @@ -1,36 +1,19 @@ +# 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 = '') { + 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 = preg_replace('|/[^/]*$|', "/$url", this_url()); + } + } + + if(function_exists('session_save_messages')) { + if(function_exists('atexit_now')) { + atexit_now(); + } + session_save_messages(); + } + + header("HTTP/1.0 $status"); + header("Location: $url"); + echo($message); + exit(); +} + +# output http headers to allow caching of this page forever +function http_cache_forever($cache_control = 'public') { + header('Last-Modified: '.gmdate('D, d M Y H:i:s', 5025) . ' GMT'); # long time ago + header("Cache-Control: $cache_control"); + header('Expires: ' . gmdate('D, d M Y H:i:s',time()+31536000) . ' GMT'); # rfc 2616 says not to go more than a year in the future +}