News:

Dear forum visitors, if the support forum is not available, please try again a few minutes later. Thanks!

Main Menu
Support-Forum

Probable fix for php error: Undefined array key 1 in JDHelper.php

Started by baba, 05.10.2026 17:11:29

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

baba

Hey, because i cannot answer/post in the original posting i am posting a probable fix for this issue:

The warning is caused by this line:
list($home, $stuff) = explode('/', $stuff, 2);


The same problem can also occur with the site URL parsing:
list($domain, $stuff2) = explode('/', $stuff2, 2);


I probable fix might be (tested):

public static function useAntiLeeching()
{
    $app = Factory::getApplication();
    $params = $app->getParams();

    $baseUri = Uri::getInstance(Uri::base(false));
    $domain = strtolower($baseUri->getHost());
    $domain = preg_replace('/^www\./i', '', $domain);

    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    $refererUri = $referer !== '' ? Uri::getInstance($referer) : null;

    $home = '';
    if ($refererUri !== null) {
        $home = strtolower($refererUri->getHost());
        $home = preg_replace('/^www\./i', '', $home);
    }

    $blocking = false;

    if ($params->get('check_leeching')) {
        if ($referer === '') {
            $blocking = (bool) $params->get('block_referer_is_empty');
        } elseif ($home !== '' && $home !== $domain) {
            $allowedUrls = array_filter(array_map(
                static function ($host) {
                    $host = strtolower(trim($host));
                    return preg_replace('/^www\./i', '', $host);
                },
                explode(',', (string) $params->get('allowed_leeching_sites', ''))
            ));

            if (!in_array($home, $allowedUrls, true)) {
                $blocking = true;
            }
        }
    }

    // Check blacklist
    if ($params->get('use_blocking_list')
        && $params->get('blocking_list') !== '') {

        $userIp = self::getRealIp();
        $blockingList = explode(
            "\n",
            str_replace("\r", '', (string) $params->get('blocking_list'))
        );

        if (self::inIpRange($userIp, $blockingList)) {
            $blocking = true;
        }
    }

    return $blocking;
}


Replace the block
public static function useAntiLeeching()
!
Please test & verify!
  •  

Arno

Hi Baba,
thank you for reporting this and sharing your proposed solution.

We have reproduced the PHP warning when the referrer is missing or contains a host without a trailing slash. A narrowly scoped fix is now included in the upcoming 4.1.8 release: missing URL parts are handled without generating warnings.

We have deliberately preserved the existing blocking and allowlist behaviour rather than adopting the complete replacement function. Your additional suggestions regarding host normalization and empty-referrer handling have been noted for separate review.

Thanks again for your contribution.
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!
  •