diff --git a/inc/config.php b/inc/config.php index 8f6fdf0e..f8b31c0d 100644 --- a/inc/config.php +++ b/inc/config.php @@ -635,7 +635,10 @@ // The root directory, including the trailing slash, for Tinyboard. // examples: '/', 'http://boards.chan.org/', '/chan/' - $config['root'] = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) == '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/'); + if(isset($_SERVER['REQUEST_URI'])) + $config['root'] = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) == '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/'); + else + $config['root'] = '/'; // CLI mode // If for some reason the folders and static HTML index files aren't in the current working direcotry, // enter the directory path here. Otherwise, keep it false. diff --git a/inc/functions.php b/inc/functions.php index d7136fa7..12b51d25 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -45,24 +45,28 @@ $config['post_url'] = $config['root'] . $config['file_post']; if(!isset($config['referer_match'])) - $config['referer_match'] = '/^' . - (preg_match($config['url_regex'], $config['root']) ? '' : - 'https?:\/\/' . $_SERVER['HTTP_HOST']) . - preg_quote($config['root'], '/') . - '(' . - str_replace('%s', '\w+', preg_quote($config['board_path'], '/')) . - '(' . - preg_quote($config['file_index'], '/') . '|' . - str_replace('%d', '\d+', preg_quote($config['file_page'])) . - ')?' . - '|' . - str_replace('%s', '\w+', preg_quote($config['board_path'], '/')) . - preg_quote($config['dir']['res'], '/') . - str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . - '|' . - preg_quote($config['file_mod'], '/') . '\?\/.+' . - ')([#?](.+)?)?$/i'; - + if(isset($_SERVER['HTTP_HOST'])) { + $config['referer_match'] = '/^' . + (preg_match($config['url_regex'], $config['root']) ? '' : + 'https?:\/\/' . $_SERVER['HTTP_HOST']) . + preg_quote($config['root'], '/') . + '(' . + str_replace('%s', '\w+', preg_quote($config['board_path'], '/')) . + '(' . + preg_quote($config['file_index'], '/') . '|' . + str_replace('%d', '\d+', preg_quote($config['file_page'])) . + ')?' . + '|' . + str_replace('%s', '\w+', preg_quote($config['board_path'], '/')) . + preg_quote($config['dir']['res'], '/') . + str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . + '|' . + preg_quote($config['file_mod'], '/') . '\?\/.+' . + ')([#?](.+)?)?$/i'; + } else { + // CLI mode + $config['referer_match'] = '//'; + } if(!isset($config['cookies']['path'])) $config['cookies']['path'] = &$config['root'];