Skip to content

Commit 616ffd1

Browse files
committed
filter $_SERVER vars
1 parent 1773b7c commit 616ffd1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/URLHelper.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
class URLHelper {
88
public static function isSecure() : bool {
9-
return ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) ||
10-
$_SERVER['SERVER_PORT'] == 443;
9+
return ( ! empty( filter_input( INPUT_SERVER, 'HTTPS' ) ) &&
10+
filter_input( INPUT_SERVER, 'HTTPS' ) !== 'off' ) ||
11+
filter_input( INPUT_SERVER, 'SERVER_PORT' ) == 443;
1112
}
1213

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

2223
// Only include port number if needed
23-
if ( ! in_array( $_SERVER['SERVER_PORT'], [ 80, 443 ] ) ) {
24-
$url .= ':' . $_SERVER['SERVER_PORT'];
24+
if ( ! in_array( filter_input( INPUT_SERVER, 'SERVER_PORT' ), [ 80, 443 ] ) ) {
25+
$url .= ':' . filter_input( INPUT_SERVER, 'SERVER_PORT' );
2526
}
2627

27-
$url .= $_SERVER['REQUEST_URI'];
28+
$url .= filter_input( INPUT_SERVER, 'REQUEST_URI' );
2829

2930
return $url;
3031
}

0 commit comments

Comments
 (0)