diff --git a/api/cron.php b/api/cron.php
index 0ca641b52062d6a817f67d49297e9e062d63f31b..f5d47e43e2af43e1d26a1f8a5e9af698bc7e0b8f 100644
--- a/api/cron.php
+++ b/api/cron.php
@@ -19,8 +19,6 @@ require('api.inc.php');
 if (!osTicket::is_cli())
     die('cron.php only supports local cron calls - use http -> api/tasks/cron');
 
-@chdir(realpath(dirname(__FILE__)).'/'); //Change dir.
-require('api.inc.php');
 require_once(INCLUDE_DIR.'api.cron.php');
 LocalCronApiController::call();
 ?>
diff --git a/bootstrap.php b/bootstrap.php
index e99b1e339c1216ea3e5f03dcd78eb090465f1bbe..d050960ed4ffdeb0443e5878029d3539e625901f 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -43,6 +43,9 @@ class Bootstrap {
                 ini_set('date.timezone', 'America/New_York');
             }
         }
+
+        if (!isset($_SERVER['REMOTE_ADDR']))
+            $_SERVER['REMOTE_ADDR'] = '';
     }
 
     function https() {
diff --git a/include/class.osticket.php b/include/class.osticket.php
index 467831d5b6e4a10720010d3a5f2a223a91257087..10f16bf95c370273799e0c5dc85b063671a07db1 100644
--- a/include/class.osticket.php
+++ b/include/class.osticket.php
@@ -367,7 +367,7 @@ class osTicket {
          * Secondly, if the directory of main.inc.php is the same as the
          * document root, the the ROOT path truly is '/'
          */
-        if(!$_SERVER['DOCUMENT_ROOT']
+        if(!isset($_SERVER['DOCUMENT_ROOT'])
                 || !strcasecmp($_SERVER['DOCUMENT_ROOT'], $dir))
             return '/';
 
@@ -411,7 +411,9 @@ class osTicket {
     /* returns true if script is being executed via commandline */
     function is_cli() {
         return (!strcasecmp(substr(php_sapi_name(), 0, 3), 'cli')
-                || (!$_SERVER['REQUEST_METHOD'] && !$_SERVER['HTTP_HOST']) //Fallback when php-cgi binary is used via cli
+                || (!isset($_SERVER['REQUEST_METHOD']) &&
+                    !isset($_SERVER['HTTP_HOST']))
+                    //Fallback when php-cgi binary is used via cli
                 );
     }
 
diff --git a/main.inc.php b/main.inc.php
index 56da2cb710261bb7fa21c04c700aa9823981f669..e62d6e5e43bec6fed2bdee435005c9eae94c6d44 100644
--- a/main.inc.php
+++ b/main.inc.php
@@ -16,7 +16,9 @@ vim: expandtab sw=4 ts=4 sts=4:
 **********************************************************************/
 
 #Disable direct access.
-if(!strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__))) die('kwaheri rafiki!');
+if(isset($_SERVER['SCRIPT_NAME'])
+        && !strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__)))
+    die('kwaheri rafiki!');
 
 require('bootstrap.php');
 Bootstrap::loadConfig();