Skip to content

Commit

Permalink
filter $_SERVER vars
Browse files Browse the repository at this point in the history
  • Loading branch information
leonstafford committed Jan 31, 2023
1 parent 1773b7c commit 616ffd1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/URLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

class URLHelper {
public static function isSecure() : bool {
return ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) ||
$_SERVER['SERVER_PORT'] == 443;
return ( ! empty( filter_input( INPUT_SERVER, 'HTTPS' ) ) &&
filter_input( INPUT_SERVER, 'HTTPS' ) !== 'off' ) ||
filter_input( INPUT_SERVER, 'SERVER_PORT' ) == 443;
}

/*
Expand All @@ -17,14 +18,14 @@ public static function isSecure() : bool {
*/
public static function getCurrent() : string {
$scheme = self::isSecure() ? 'https' : 'http';
$url = $scheme . '://' . $_SERVER['HTTP_HOST'];
$url = $scheme . '://' . filter_input( INPUT_SERVER, 'HTTP_HOST' );

// Only include port number if needed
if ( ! in_array( $_SERVER['SERVER_PORT'], [ 80, 443 ] ) ) {
$url .= ':' . $_SERVER['SERVER_PORT'];
if ( ! in_array( filter_input( INPUT_SERVER, 'SERVER_PORT' ), [ 80, 443 ] ) ) {
$url .= ':' . filter_input( INPUT_SERVER, 'SERVER_PORT' );
}

$url .= $_SERVER['REQUEST_URI'];
$url .= filter_input( INPUT_SERVER, 'REQUEST_URI' );

return $url;
}
Expand Down

0 comments on commit 616ffd1

Please sign in to comment.