Skip to content

Commit

Permalink
Undefined index REQUEST_METHOD and HTTP_HOST while running the cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-perl committed Feb 17, 2017
2 parents d78f38d + 61b1733 commit 01c4d33
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions libraries/router.php
Expand Up @@ -28,24 +28,14 @@ public static function instance()

protected function parse()
{

if (PHP_SAPI != 'cli') {
$this->method = $_SERVER['REQUEST_METHOD'];
$this->host = $_SERVER['HTTP_HOST'];
} else {
$this->method = self::GET;
$this->host = null;
}

$this->protocol = (
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off')
|| (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
) ? 'https' : 'http';
$this->baseUrl = $this->protocol.'://'.$this->host;
$this->url = $this->protocol.'://'.$this->host.$_SERVER['SCRIPT_NAME'];
$this->path = '';
$this->host = '';
$this->method = self::GET;

if (PHP_SAPI != 'cli') {
$this->host = $_SERVER['HTTP_HOST'];
$this->method = $_SERVER['REQUEST_METHOD'];

$this->path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']);
Log::factory()->write(Log::INFO, $_SERVER['REQUEST_URI'], 'Router');

Expand All @@ -56,6 +46,8 @@ protected function parse()
$this->path = $_SERVER['argv'][1];
}

$this->baseUrl = '//'.$this->host;
$this->url = '//'.$this->host.$_SERVER['SCRIPT_NAME'];
$this->request = $this->url.$this->path;

if (preg_match('/^(.*)\/(.*)$/', $_SERVER['SCRIPT_NAME'], $matches)) {
Expand Down

0 comments on commit 01c4d33

Please sign in to comment.