/** * Updates the current directories we have with the correct path and * also does some other needed startup things such as setting the autoloader * storing CWD, getting temp dir etc etc * * @param string $rootDir * @param string $state * @return object */ private function __construct($rootDir, $state = 'production') { $this->cwd = getcwd(); $this->state = (string) $state; if (zula_http_header_get('X-Requested-With') == 'XMLHttpRequest' || zula_http_header_get('X-Zula-Mode') == 'standalone') { $this->mode = 'standalone'; } else { $this->mode = PHP_SAPI == 'cli' ? 'cli' : 'normal'; } set_exception_handler(array($this, 'exceptionHandler')); spl_autoload_register(array(__CLASS__, 'autoloadClass')); /** * Get the base directory (path from the URL) and update directories * with the root directory prefix. */ // Configure the base directory $base = trim(dirname($_SERVER['SCRIPT_NAME']), './\\ '); define('_BASE_DIR', empty($base) ? '/' : '/' . $base . '/'); foreach ($this->directories as $name => $path) { if (substr($path, 0, 2) !== './') { $path = $rootDir . '/' . $path; } $this->updateDir($name, $path); } }
/** * Gets the remote client IP address * * @return string */ function zula_get_client_ip() { if (($ip = zula_http_header_get('Client-Ip')) || ($ip = zula_http_header_get('X-Forwarded-For'))) { $split = explode(',', $ip); return $split[0]; } else { if (empty($_SERVER['REMOTE_ADDR'])) { return '127.0.0.1'; } else { return $_SERVER['REMOTE_ADDR']; } } }