Skip to content

Commit

Permalink
Fix potential problem with some absent HTTP request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
faf committed Dec 3, 2021
1 parent cd1e8ad commit 5a4d3d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/mibew/libs/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/mibew/libs/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
*/
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";

Expand Down

0 comments on commit 5a4d3d4

Please sign in to comment.