[pLog-svn] r962 - in plog/trunk: . class/net/http class/net/http/session

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sun Feb 6 14:44:59 GMT 2005


Author: oscar
Date: 2005-02-06 14:44:58 +0000 (Sun, 06 Feb 2005)
New Revision: 962

Added:
   plog/trunk/class/net/http/session/
   plog/trunk/class/net/http/session/sessionmanager.class.php
Modified:
   plog/trunk/admin.php
   plog/trunk/index.php
Log:
added a session manager which will take care of setting the session cookie path, cookie domain, cookie lifetime if needed, etc. I've also removed all the cookie stuff from admin.php and index.php and moved all the logic to SessionManager but unfortunately, it does not work very well if I enable the code that sets the cookie domain... there must definitely be something wrong.

Modified: plog/trunk/admin.php
===================================================================
--- plog/trunk/admin.php	2005-02-06 14:36:16 UTC (rev 961)
+++ plog/trunk/admin.php	2005-02-06 14:44:58 UTC (rev 962)
@@ -4,8 +4,7 @@
     }
 
     include_once( PLOG_CLASS_PATH."class/controller/admincontroller.class.php" );
-    include_once( PLOG_CLASS_PATH."class/net/sessioninfo.class.php" );
-    include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
+	include_once( PLOG_CLASS_PATH."class/net/http/session/sessionmanager.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
     include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
@@ -16,25 +15,15 @@
     //
     // a security check, or else people might forget to remove the wizard.php script
     //
-    if( File::isReadable( "wizard.php")) {
+/*    if( File::isReadable( "wizard.php")) {
         print("<span style=\"color:red\">The wizard.php script has to be removed after the installation process.</span><br/><br/>
                Please remove it first to continue.");
         die();
-    }
+    }*/
 
-    //session_cache_limiter( "public" );
-    session_name( "plog_session" );
-    session_start();
+	// initialize the session
+	SessionManager::init();
 
-    //
-    // if there is no session object, we better create one
-    //
-    $session = HttpVars::getSession();
-    if( !isset($session["SessionInfo"])) {
-        $session["SessionInfo"] = new SessionInfo();
-        HttpVars::setSession( $session );
-    }
-
     $controller = new AdminController();
 
     // load the plugins, this needs to be done *before* we call the

Added: plog/trunk/class/net/http/session/sessionmanager.class.php
===================================================================
--- plog/trunk/class/net/http/session/sessionmanager.class.php	2005-02-06 14:36:16 UTC (rev 961)
+++ plog/trunk/class/net/http/session/sessionmanager.class.php	2005-02-06 14:44:58 UTC (rev 962)
@@ -0,0 +1,85 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
+	include_once( PLOG_CLASS_PATH."class/net/sessioninfo.class.php" );
+	
+	/**
+	 * @package session
+	 */
+
+	/**
+	 * deals with session, initializing, session cookies, etc
+	 */
+	class SessionManager extends Object
+	{
+	
+		/**
+		 * static method that takes care of initializing a session if there is none yet
+		 *
+		 * @return nothing
+		 * @static
+		 * @see SessionInfo
+		 */
+		function init()
+		{
+			// this needs to be done before the session is started
+			SessionManager::setSessionCookiePath();
+			//SessionManager::setSessionCookieDomain();
+		
+			//session_cache_limiter( "public" );
+			session_name( "plog_session" );
+			session_start();
+
+			//
+			// if there is no session object, we better create one
+			//
+			$session = HttpVars::getSession();
+			if( $session["SessionInfo"] == "" ) {
+				$session["SessionInfo"] = new SessionInfo();
+				HttpVars::setSession( $session );
+			}		
+		}
+		
+		/**
+		 * @private
+		 * @static
+		 * Sets the session cookie path to the right path
+		 * @return nothing
+		 */
+		function setSessionCookiePath()
+		{			
+			// get the right url for the script... somehow $_SERVER["REQUEST_URI"]
+			// is returning things like "http://83.102.183.10.in-addr.arpa/plog/test.php"
+			// in my case which are correct but probably not what we're expecting!
+			$server = HttpVars::getServer();
+			$scriptUrl = "http://".$server["HTTP_HOST"].$server["SCRIPT_URL"];
+			$url = new Url( $scriptUrl );
+			$path = dirname($url->getPath());
+			if( $path == "" ) 
+				$path = "/";
+				
+			$log =& LoggerManager::getLogger();
+			$log->debug("cookie path = $path");
+		
+			ini_set( "session.cookie_path", $path );
+		}
+		
+		/**
+		 * @private
+		 * @static
+		 * Sets the right domain for the cookie
+		 * @return nothing
+		 */
+		function setSessionCookieDomain()
+		{
+			$server = HttpVars::getServer();
+			$domain = $server["HTTP_HOST"];
+
+			$log =& LoggerManager::getLogger();
+			$log->debug("cookie domain = $domain");			
+			
+			ini_set( "session.cookie_domain", $domain );
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/index.php
===================================================================
--- plog/trunk/index.php	2005-02-06 14:36:16 UTC (rev 961)
+++ plog/trunk/index.php	2005-02-06 14:44:58 UTC (rev 962)
@@ -7,8 +7,7 @@
     }
 
     include_once( PLOG_CLASS_PATH."class/controller/blogcontroller.class.php" );
-    include_once( PLOG_CLASS_PATH."class/net/sessioninfo.class.php" );
-    include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
+	include_once( PLOG_CLASS_PATH."class/net/http/session/sessionmanager.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
     include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
@@ -21,25 +20,15 @@
     //
     // a security check, or else people might forget to remove the wizard.php script
     //
-    if( File::isReadable( "wizard.php")) {
+/*    if( File::isReadable( "wizard.php")) {
         print("<span style=\"color:red\">The wizard.php script has to be removed after the installation process.</span><br/><br/>
                Please remove it first to continue.");
         die();
-    }
+    }*/
+	
+	// initialize the session
+	SessionManager::init();
 
-	//session_cache_limiter( "public" );
-    session_name( "plog_session" );
-    session_start();
-
-    //
-    // if there is no session object, we better create one
-    //
-    $session = HttpVars::getSession();
-    if( $session["SessionInfo"] == "" ) {
-        $session["SessionInfo"] = new SessionInfo();
-        HttpVars::setSession( $session );
-    }
-
     $controller = new BlogController();
 
     // load the plugins, this needs to be done *before* we call the




More information about the pLog-svn mailing list