JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
changed licence to lgpl, metaform includes wfpl in tarbal
[wfpl.git] / http.php
1 <?php
2
3 #  Copyright (C) 2005 Jason Woofenden
4 #
5 #  This file is part of wfpl.
6 #
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)
10 #  any later version.
11 #
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
15 #  more details.
16 #
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
20
21
22 # return our best guess at the url used to access this page
23 function this_url() {
24         list($protocol, $version) = explode('/', $_SERVER['SERVER_PROTOCOL']);
25         $url = strtolower($protocol);
26
27         if($url == 'http') {
28                 $expected_port = 80;
29         } elseif ($url == 'https') {
30                 $expected_port = 443;
31         } else {
32                 $expected_port = -1;
33         }
34
35         $url .= '://';
36         if($_SERVER['HTTP_HOST']) {
37                 $url .= $_SERVER['HTTP_HOST'];
38         } else {
39                 $url .= $_SERVER['SERVER_NAME'];
40                 if($_SERVER['SERVER_PORT'] != $expected_port) {
41                         $url .= ':' . $_SERVER['SERVER_PORT'];
42                 }
43         }
44
45         $url .= $_SERVER['REQUEST_URI'];
46
47         return $url;
48 }
49
50 function redirect($url, $status = '302 Moved Temporarily', $message = '') {
51         header("HTTP/1.1 $status");
52         header("Location: $url");
53         echo($message);
54         exit();
55 }
56
57 ?>