Fix potential problem with some absent HTTP request headers

This commit is contained in:
Fedor A. Fetisov 2021-12-03 20:20:40 +03:00
parent cd1e8adce3
commit 5a4d3d420f
2 changed files with 7 additions and 3 deletions

View File

@ -609,9 +609,11 @@ function visitor_from_request()
*/
function get_remote_host()
{
$ext_addr = $_SERVER['REMOTE_ADDR'];
$ext_addr = isset($_SERVER['REMOTE_ADDR'])
? $_SERVER['REMOTE_ADDR']
: '';
$has_proxy = isset($_SERVER['HTTP_X_FORWARDED_FOR'])
&& $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR'];
&& $_SERVER['HTTP_X_FORWARDED_FOR'] != $ext_addr;
if ($has_proxy) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
$ext_addr = (count($ips) > 1)

View File

@ -36,7 +36,9 @@ define('PAGINATION_LINKS_ON_PAGE', 5);
*/
function generate_pagination_link($page, $title)
{
$lnk = $_SERVER['REQUEST_URI'];
$lnk = isset($_SERVER['REQUEST_URI'])
? $_SERVER['REQUEST_URI']
: '';
$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
$href .= strstr($href, "?") ? "&page=$page" : "?page=$page";