Skip to content

Commit 8f69c37

Browse files
committed
[PHP Compatibility]Fix: Add PHP 8.0+ compatibility for installer superglobal access
Add null coalescing operators (??) to all array access in installer Fix _install/constants.php - 7 key accesses Fix _install/data/configs/constants.php - 7 key accesses Fix _install/library/Language.class.php - HTTP_ACCEPT_LANGUAGE access Fix WebsiteChecker.php - PHP_SELF access Prevents 'Undefined array key' warnings in PHP 8.0+ Ensures installer works correctly on PHP 8.0-8.5 All installer files now fully compatible with PHP 8.0+.
1 parent 3cbea08 commit 8f69c37

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

WebsiteChecker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @author Pierre-Henry Soria <hello@ph7builder.com>
4-
* @copyright (c) 2018-2023, Pierre-Henry Soria. All Rights Reserved.
4+
* @copyright (c) 2018-2026, Pierre-Henry Soria. All Rights Reserved.
55
* @license See LICENSE.md and COPYRIGHT.md in the root directory.
66
* @link https://ph7builder.com
77
* @package PH7 / ROOT
@@ -55,7 +55,7 @@ public function clearBrowserCache(): void
5555
public function moveToInstaller(): void
5656
{
5757
// Remove backslashes for Windows compatibility
58-
$sUrlPath = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES)));
58+
$sUrlPath = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'] ?? '', ENT_QUOTES)));
5959
$sUrlPath = substr($sUrlPath, -1) !== '/' ? $sUrlPath . '/' : $sUrlPath;
6060

6161
header('Location: ' . $sUrlPath . self::INSTALL_FOLDER_NAME);

_install/constants.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @author Pierre-Henry Soria <hello@ph7builder.com>
4-
* @copyright (c) 2012-2023, Pierre-Henry Soria. All Rights Reserved.
4+
* @copyright (c) 2012-2026, Pierre-Henry Soria. All Rights Reserved.
55
* @license MIT License; See LICENSE.md and COPYRIGHT.md in the root directory.
66
*/
77

@@ -16,15 +16,15 @@
1616
(!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') ||
1717
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
1818
(!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') ||
19-
$_SERVER['SERVER_PORT'] === '443'
19+
($_SERVER['SERVER_PORT'] ?? '') === '443'
2020
) ? 'https://' : 'http://';
2121

2222
// Determine the domain name, with the port if necessary
23-
$sServerName = $_SERVER['SERVER_NAME'] !== $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
24-
$sDomain = ($_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' && strpos($sServerName, ':') === false) ? $sServerName . ':' . $_SERVER['SERVER_PORT'] : $sServerName;
23+
$sServerName = ($_SERVER['SERVER_NAME'] ?? '') !== ($_SERVER['HTTP_HOST'] ?? '') ? ($_SERVER['HTTP_HOST'] ?? '') : ($_SERVER['SERVER_NAME'] ?? '');
24+
$sDomain = (($_SERVER['SERVER_PORT'] ?? '') !== '80' && ($_SERVER['SERVER_PORT'] ?? '') !== '443' && strpos($sServerName, ':') === false) ? $sServerName . ':' . ($_SERVER['SERVER_PORT'] ?? '') : $sServerName;
2525

2626
// Determine the current file of the application
27-
$sPhp_self = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES))); // Remove backslashes for Windows compatibility
27+
$sPhp_self = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'] ?? '', ENT_QUOTES))); // Remove backslashes for Windows compatibility
2828

2929
//---------- Constants ----------//
3030

_install/data/configs/constants.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @author Pierre-Henry Soria <hello@ph7builder.com>
4-
* @copyright (c) 2012-2023, Pierre-Henry Soria. All Rights Reserved.
4+
* @copyright (c) 2012-2026, Pierre-Henry Soria. All Rights Reserved.
55
* @license MIT License; See LICENSE.md and COPYRIGHT.md in the root directory.
66
* @link https://ph7builder.com
77
* @package PH7
@@ -19,19 +19,19 @@
1919
(!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') ||
2020
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
2121
(!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') ||
22-
$_SERVER['SERVER_PORT'] === '443'
22+
($_SERVER['SERVER_PORT'] ?? '') === '443'
2323
) ? 'https://' : 'http://';
2424

2525
// Determine the domain name, with the port if necessary
26-
$sServerName = $_SERVER['SERVER_NAME'] !== $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
27-
$sDomain = ($_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' && strpos($sServerName, ':') === false) ? $sServerName . ':' . $_SERVER['SERVER_PORT'] : $sServerName;
26+
$sServerName = ($_SERVER['SERVER_NAME'] ?? '') !== ($_SERVER['HTTP_HOST'] ?? '') ? ($_SERVER['HTTP_HOST'] ?? '') : ($_SERVER['SERVER_NAME'] ?? '');
27+
$sDomain = (($_SERVER['SERVER_PORT'] ?? '') !== '80' && ($_SERVER['SERVER_PORT'] ?? '') !== '443' && strpos($sServerName, ':') === false) ? $sServerName . ':' . ($_SERVER['SERVER_PORT'] ?? '') : $sServerName;
2828

2929
// Get the domain that the cookie and cookie session is available (Set-Cookie: domain=your_site_name.com)
30-
// $sDomain_cookie = (substr($_SERVER['HTTP_HOST'], 0, 4) === 'www.') ? '.' . substr($_SERVER['HTTP_HOST'], 4) : '.' . $_SERVER['HTTP_HOST'];
30+
// $sDomain_cookie = (substr($_SERVER['HTTP_HOST'] ?? '', 0, 4) === 'www.') ? '.' . substr($_SERVER['HTTP_HOST'] ?? '', 4) : '.' . ($_SERVER['HTTP_HOST'] ?? '');
3131
$sDomain_cookie = '.' . str_replace('www.', '', $sDomain);
3232

3333
// Determine the current file of the application
34-
$sPhp_self = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES))); // Remove backslashes for Windows compatibility
34+
$sPhp_self = str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'] ?? '', ENT_QUOTES))); // Remove backslashes for Windows compatibility
3535

3636

3737
########## CONSTANTS ##########

_install/library/Language.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @title Language Class
44
*
55
* @author Pierre-Henry Soria <ph7software@gmail.com>
6-
* @copyright (c) 2012-2019, Pierre-Henry Soria. All Rights Reserved.
6+
* @copyright (c) 2012-2026, Pierre-Henry Soria. All Rights Reserved.
77
* @license MIT License; See LICENSE.md and COPYRIGHT.md in the root directory.
88
* @package PH7 / Install / Library
99
*/
@@ -49,7 +49,7 @@ public function getBrowser(): ?string
4949
return null;
5050
}
5151

52-
$sLang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'])[0];
52+
$sLang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '')[0];
5353

5454
return htmlspecialchars(
5555
strtolower(

0 commit comments

Comments
 (0)