+/**
+ * Secures $_SERVER['PHP_SELF'] against attacks
+ *
+ * @return void
+ */
+function securePhpSelf () {
+ // Did it run before?
+ if (isset($GLOBALS['php_self_secured'])) {
+ // Please do not call this twice!
+ die('PHP_SELF is already secured. Please do not call ' . __FUNCTION__ . ' for your self.');
+ } // END - if
+
+ // Secure the string
+ $_SERVER['PHP_SELF'] = secureString($_SERVER['PHP_SELF']);
+
+ // Split it up into path and filename
+ $phpSelfDirectory = dirname($_SERVER['PHP_SELF']);
+ $phpSelfFile = basename($_SERVER['PHP_SELF']);
+
+ // Check for a .php inside the $phpSelfDirectory...
+ while (strpos($phpSelfDirectory, '.php') !== false) {
+ // Correct the dirname
+ $phpSelfDirectory = substr($phpSelfDirectory, 0, (strpos($phpSelfDirectory, '.php') + 4));
+ // Rewrite filename...
+ $phpSelfFile = basename($phpSelfDirectory);
+ // ... and dirname
+ $phpSelfDirectory = dirname($phpSelfDirectory);
+ } // END - while
+
+ // Put both together again and let's pray it is secured now...
+ $_SERVER['PHP_SELF'] = $phpSelfDirectory . '/' . $phpSelfFile;
+
+ // Did run...
+ $GLOBALS['php_self_secured'] = true;
+
+ // Remove uneccessary variables
+ unset($phpSelfDirectory);
+ unset($phpSelfFile);
+}
+
+/**
+ * Detects caching in PHP
+ *
+ * @return void
+ */
+function detectPhpCaching () {
+ // Activate caching or transparent compressing when it is not already done
+ if (phpversion() >= '4.0.4pl1' && (strstr(getenv('HTTP_USER_AGENT'),'compatible') || (strstr(getenv('HTTP_USER_AGENT'), 'Mozilla')))) {
+ if ((extension_loaded('zlib')) && (function_exists('ob_start'))) {
+ // Start caching
+ $GLOBALS['php_caching'] = 'on';
+ ob_start();
+ } else {
+ // Extension not loaded or required function is missing
+ $GLOBALS['php_caching'] = '404';
+ }
+ } else {
+ // Old PHP version
+ $GLOBALS['php_caching'] = 'old';
+ }
+}