JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
initial import (from revision 1199 + email.php)
[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
8 #  under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2, or (at your option)
10 #  any later version.
11 #
12 #  wfpl is distributed in the hope that it will be useful, but
13 #  WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  General Public License for more details.
16 #
17 #  You should have received a copy of the GNU General Public License
18 #  along with wfpl; see the file COPYING.  If not, write to the
19 #  Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 #  MA 02111-1307, USA.
21
22
23 # return our best guess at the url used to access this page
24 function this_url() {
25         list($protocol, $version) = explode('/', $_SERVER['SERVER_PROTOCOL']);
26         $url = strtolower($protocol);
27
28         if($url == 'http') {
29                 $expected_port = 80;
30         } elseif ($url == 'https') {
31                 $expected_port = 443;
32         } else {
33                 $expected_port = -1;
34         }
35
36         $url .= '://';
37         if($_SERVER['HTTP_HOST']) {
38                 $url .= $_SERVER['HTTP_HOST'];
39         } else {
40                 $url .= $_SERVER['SERVER_NAME'];
41                 if($_SERVER['SERVER_PORT'] != $expected_port) {
42                         $url .= ':' . $_SERVER['SERVER_PORT'];
43                 }
44         }
45
46         $url .= $_SERVER['REQUEST_URI'];
47
48         return $url;
49 }
50
51 ?>