JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed session_purge_old() and session_messages.php, redirect() can now take just...
authorJason Woofenden <jason183@herkamire.com>
Thu, 14 Jun 2007 11:41:00 +0000 (07:41 -0400)
committerJason Woofenden <jason183@herkamire.com>
Thu, 14 Jun 2007 11:41:00 +0000 (07:41 -0400)
http.php
session.php
session_messages.php

index c7c457a..94dbff1 100644 (file)
--- a/http.php
+++ b/http.php
@@ -19,8 +19,8 @@
 #  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);
 
@@ -42,15 +42,37 @@ function this_url() {
                }
        }
 
+       return $url;
+}
+
+# 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)
 function redirect($url, $status = '302 Moved Temporarily', $message = '') {
+       if(!strpos($url, ':')) {
+               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);
index c3be9e9..b04ed57 100644 (file)
@@ -100,7 +100,7 @@ function _kill_session($id) {
 # delete expired sessions from database
 function session_purge_old() {
        $now = time();
-       $exired_sessions = db_get_column('wfpl_sessions', 'id', 'where expires < %i', $now);
+       $expired_sessions = db_get_column('wfpl_sessions', 'id', 'where expires < %i', $now);
        if($expired_sessions) foreach($expired_sessions as $expired_session) {
                _kill_session($expired_session);
        }
@@ -112,6 +112,10 @@ function session_exists() {
                return false;
        }
 
+       if(isset($GLOBALS['session_id'])) {
+               return true;
+       }
+
        $session_key = ereg_replace('[^a-zA-Z0-9]', '', $_REQUEST['session_key']);
 
        if(!strlen($session_key) == 16) {
index 358994c..c3e16f0 100644 (file)
@@ -39,18 +39,22 @@ function session_save_messages() {
        }
 
        init_session();
-       session_set('wfpl_messages', array_to_string($GLOBALS['wfpl_messages']);
+       session_set('wfpl_messages', array_to_string($GLOBALS['wfpl_messages']));
 }
 
 function session_restore_messages() {
-       if(!session()) {
+       if(!session_exists()) {
                return false;
        }
        $messages = session_get('wfpl_messages');
        if($messages !== false) {
                $messages = string_to_array($messages);
+               if(!(isset($GLOBALS['wfpl_messages']) && is_array($GLOBALS['wfpl_messages']))) {
+                       $GLOBALS['wfpl_messages'] = array();
+               }
                # messages from the previous run happened first
                $GLOBALS['wfpl_messages'] = array_merge($messages, $GLOBALS['wfpl_messages']);
+
        }
        session_clear('wfpl_messages');
 }