X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=http.php;h=51eb4d39f5d6d797a0a3e2d46a0a65b6163ed8be;hp=94dbff17b302e4ebd36047498e1d4304f8e8dda9;hb=15459c86d0996ab3037b1738a8be6efd378c1258;hpb=4f94560f060a7305ea791def3950adb1bda092ec diff --git a/http.php b/http.php index 94dbff1..51eb4d3 100644 --- a/http.php +++ b/http.php @@ -2,34 +2,28 @@ # Copyright (C) 2005 Jason Woofenden # -# This file is part of wfpl. -# -# wfpl is free software; you can redistribute it and/or modify it under the -# terms of the GNU Lesser General Public License as published by the Free -# Software Foundation; either version 2.1 of the License, or (at your option) -# any later version. -# -# wfpl is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for -# more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with wfpl; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . # 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); - - if($url == 'http') { - $expected_port = 80; - } elseif ($url == 'https') { + if(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == 'yes') { + $url = 'https'; $expected_port = 443; } else { - $expected_port = -1; + $url = 'http'; + $expected_port = 80; } $url .= '://'; @@ -45,6 +39,22 @@ function this_url_sans_path() { return $url; } +# just the hostname, no port number +function this_host() { + if($_SERVER['HTTP_HOST']) { + $host = $_SERVER['HTTP_HOST']; + $p = strpos($host, ':'); + if($p) { + $host = substr($host, 0, $p); + } + return $host; + } else { + return $_SERVER['SERVER_NAME']; + } +} + + + # return our best guess at the url used to access this page function this_url() { $url = this_url_sans_path(); @@ -59,17 +69,23 @@ function this_url() { # $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) +# 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 = ereg_replace('/[^/]*([?].*)?$', "/$url", this_url()); + $url = ereg_replace('/[^/]*$', "/$url", this_url()); } } if(function_exists('session_save_messages')) { + if(function_exists('atexit_now')) { + atexit_now(); + } session_save_messages(); } @@ -79,4 +95,11 @@ function redirect($url, $status = '302 Moved Temporarily', $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 +} + ?>