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 751dc7a..65eba41 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 8f6fa15..e7dfb69 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;
@@ -257,6 +257,24 @@ class FrameworkConfiguration implements Registerable {
        }
 
        /**
+        * 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
         *
         * @param       $fieldName              Field name which we shall get