Cookie path now detected by generic method
authorRoland Häder <roland@mxchange.org>
Fri, 3 Oct 2008 00:30:56 +0000 (00:30 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 3 Oct 2008 00:30:56 +0000 (00:30 +0000)
inc/config.php
inc/config/class_FrameworkConfiguration.php

index 751dc7a8661d13c6a2a1979ae0cf745287b7c523..65eba410628777f75095d58f48698c09617c8fdc 100644 (file)
@@ -267,7 +267,7 @@ $cfg->setConfigEntry('guest_class', "Guest");
 $cfg->setConfigEntry('cookie_expire', (60*60*2)); // Two hours!
 
 // CFG: COOKIE-PATH
-$cfg->setConfigEntry('cookie_path', dirname($_SERVER['SCRIPT_NAME']) . "/");
+$cfg->setConfigEntry('cookie_path', $cfg->detectScriptPath() . "/");
 
 // CFG: COOKIE-DOMAIN
 $cfg->setConfigEntry('cookie_domain', $cfg->detectDomain()); // Is mostly the same...
index 8f6fa15f45cd254137a917bb7744bd481a3974f8..e7dfb699c661148635d29fd4ad6e0b76d05c6532 100644 (file)
@@ -231,7 +231,7 @@ class FrameworkConfiguration implements Registerable {
                } // END - if
 
                // Construct the full URL now and secure it against CSRF attacks
-               $baseUrl = $baseUrl . "://" . $this->detectDomain() . dirname($_SERVER['SCRIPT_NAME']);
+               $baseUrl = $baseUrl . "://" . $this->detectDomain() . $this->detectScriptPath();
 
                // Return the URL
                return $baseUrl;
@@ -256,6 +256,24 @@ class FrameworkConfiguration implements Registerable {
                return $fullDomain;
        }
 
+       /**
+        * Detect safely the script path without trailing slash which is the part
+        * between "http://your-domain.invalid/" and "script-name.php"
+        */
+       public function detectScriptPath () {
+               // Default is empty
+               $scriptPath = "";
+
+               // Is the scriptname set?
+               if (isset($_SERVER['SCRIPT_NAME'])) {
+                       // Get dirname of it
+                       $scriptPath = dirname($_SERVER['SCRIPT_NAME']);
+               } // END - if
+
+               // Return it
+               return $scriptPath;
+       }
+
        /**
         * Getter for field name
         *