3 # Copyright (C) 2005 Jason Woofenden
5 # This file is part of wfpl.
7 # wfpl is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation; either version 2.1 of the License, or (at your option)
12 # wfpl is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with wfpl; if not, write to the Free Software Foundation, Inc., 51
19 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # return our best guess at the url used to access this page, without the path or query string
23 function this_url_sans_path() {
24 list($protocol, $version) = explode('/', $_SERVER['SERVER_PROTOCOL']);
25 $url = strtolower($protocol);
29 } elseif ($url == 'https') {
36 if($_SERVER['HTTP_HOST']) {
37 $url .= $_SERVER['HTTP_HOST'];
39 $url .= $_SERVER['SERVER_NAME'];
40 if($_SERVER['SERVER_PORT'] != $expected_port) {
41 $url .= ':' . $_SERVER['SERVER_PORT'];
48 # return our best guess at the url used to access this page
50 $url = this_url_sans_path();
52 $url .= $_SERVER['REQUEST_URI'];
57 # sends an HTTP redirect
62 # 3) a filename (you can pass a directory/file.html and such, but "../" prefix is not supported)
63 function redirect($url, $status = '302 Moved Temporarily', $message = '') {
64 if(!strpos($url, ':')) {
65 if(substr($url, 0, 1) == '/') {
66 $url = this_url_sans_path() . $url;
68 $url = ereg_replace('/[^/]*([?].*)?$', "/$url", this_url());
72 if(function_exists('session_save_messages')) {
73 session_save_messages();
76 header("HTTP/1.0 $status");
77 header("Location: $url");