jDownloads Support Forum

jDownloads for Joomla 4.x and 5.x => jDownloads 4.x - (This is the current version!) => Bugs! => Topic started by: baba on 05.10.2026 17:11:29

Title: Probable fix for php error: Undefined array key 1 in JDHelper.php
Post by: baba on 05.10.2026 17:11:29
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!
Title: Re: Probable fix for php error: Undefined array key 1 in JDHelper.php
Post by: Arno on 15.10.2026 16:25:38
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.