JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added progress-bar uploader.php
[wfpl.git] / http.php
index efc08da..042e1b9 100644 (file)
--- a/http.php
+++ b/http.php
@@ -4,24 +4,23 @@
 #
 #  This file is part of wfpl.
 #
-#  wfpl 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 2, or (at your option)
+#  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
-#  General Public License for more details.
+#  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 General Public License
-#  along with wfpl; see the file COPYING.  If not, write to the
-#  Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-#  MA 02111-1307, USA.
+#  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
 
 
-# return our best guess at the url used to access this page
-function this_url() {
+# 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);
 
@@ -43,13 +42,57 @@ function this_url() {
                }
        }
 
+       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();
+
        $url .= $_SERVER['REQUEST_URI'];
 
        return $url;
 }
 
+# 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 = '') {
-       header("HTTP/1.1 $status");
+       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());
+               }
+       }
+                       
+       if(function_exists('session_save_messages')) {
+               session_save_messages();
+       }
+
+       header("HTTP/1.0 $status");
        header("Location: $url");
        echo($message);
        exit();