Plugin Directory

Changeset 3345317


Ignore:
Timestamp:
08/15/2025 11:21:51 PM (8 months ago)
Author:
osamaesh
Message:

Fixed PHP warnings in wsm_db.php and wsm_init.php by adding safe checks for undefined host and HTTP_USER_AGENT array keys.

Location:
wp-stats-manager
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-stats-manager/tags/8.3/includes/wsm_db.php

    r3345313 r3345317  
    372372        }
    373373    }
    374     function fnReturnURLElements($url)
     374   /* function fnReturnURLElements($url)
    375375    {
    376376        //$url=strtolower($url);
     
    382382        $hash = substr(md5($newURL), 0, 16);
    383383        return array('protocol' => $arrURL['scheme'] . '://', 'url' => $newURL, 'hash' => $hash);
    384     }
     384    }*/
     385   
     386    function fnReturnURLElements($url)
     387{
     388    $url = rtrim((string) $url, "/");
     389    if ($url === '') {
     390        return array('protocol' => '', 'url' => '', 'hash' => '');
     391    }
     392
     393    $parts = @parse_url($url);
     394    if ($parts === false) {
     395
     396        $newURL = preg_replace('#^https?://#i', '', $url);
     397        $newURL = preg_replace('#^www\.#i',     '', $newURL);
     398        return array('protocol' => '', 'url' => $newURL, 'hash' => substr(md5($newURL), 0, 16));
     399    }
     400
     401    $scheme   = isset($parts['scheme']) ? $parts['scheme'] : '';
     402    $protocol = $scheme !== '' ? $scheme . '://' : '';
     403
     404
     405    $newURL = $url;
     406    if ($protocol !== '') {
     407        $newURL = preg_replace('#^' . preg_quote($protocol, '#') . '#i', '', $newURL);
     408    }
     409    $newURL = preg_replace('#^www\.#i', '', $newURL);
     410
     411    return array(
     412        'protocol' => $protocol,
     413        'url'      => $newURL,
     414        'hash'     => substr(md5($newURL), 0, 16),
     415    );
     416}
     417
     418
     419
    385420    function fnGetSearchEngineID($url)
    386421    {
  • wp-stats-manager/tags/8.3/includes/wsm_init.php

    r3345313 r3345317  
    19041904
    19051905        // User lowercase string for comparison.
    1906         $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     1906       // $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     1907       $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
     1908
    19071909
    19081910        // A list of some common words used only for bots and crawlers.
  • wp-stats-manager/trunk/includes/wsm_db.php

    r3251041 r3345317  
    372372        }
    373373    }
    374     function fnReturnURLElements($url)
     374   /* function fnReturnURLElements($url)
    375375    {
    376376        //$url=strtolower($url);
     
    382382        $hash = substr(md5($newURL), 0, 16);
    383383        return array('protocol' => $arrURL['scheme'] . '://', 'url' => $newURL, 'hash' => $hash);
    384     }
     384    }*/
     385   
     386    function fnReturnURLElements($url)
     387{
     388    $url = rtrim((string) $url, "/");
     389    if ($url === '') {
     390        return array('protocol' => '', 'url' => '', 'hash' => '');
     391    }
     392
     393    $parts = @parse_url($url);
     394    if ($parts === false) {
     395
     396        $newURL = preg_replace('#^https?://#i', '', $url);
     397        $newURL = preg_replace('#^www\.#i',     '', $newURL);
     398        return array('protocol' => '', 'url' => $newURL, 'hash' => substr(md5($newURL), 0, 16));
     399    }
     400
     401    $scheme   = isset($parts['scheme']) ? $parts['scheme'] : '';
     402    $protocol = $scheme !== '' ? $scheme . '://' : '';
     403
     404
     405    $newURL = $url;
     406    if ($protocol !== '') {
     407        $newURL = preg_replace('#^' . preg_quote($protocol, '#') . '#i', '', $newURL);
     408    }
     409    $newURL = preg_replace('#^www\.#i', '', $newURL);
     410
     411    return array(
     412        'protocol' => $protocol,
     413        'url'      => $newURL,
     414        'hash'     => substr(md5($newURL), 0, 16),
     415    );
     416}
     417
     418
     419
    385420    function fnGetSearchEngineID($url)
    386421    {
  • wp-stats-manager/trunk/includes/wsm_init.php

    r3338192 r3345317  
    19041904
    19051905        // User lowercase string for comparison.
    1906         $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     1906       // $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     1907       $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
     1908
    19071909
    19081910        // A list of some common words used only for bots and crawlers.
Note: See TracChangeset for help on using the changeset viewer.