Source of file ClientHelper.php

Size: 1,523 Bytes - Last Modified: 2020-10-24T02:46:31+00:00

/home/travis/build/NextDom/nextdom-core/src/Helpers/ClientHelper.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
<?php
/* This file is part of NextDom.
 *
 * NextDom is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NextDom is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NextDom. If not, see <http://www.gnu.org/licenses/>.
 */

namespace NextDom\Helpers;

/**
 * Class Client
 * @package NextDom\Helpers
 */
class ClientHelper
{
    /**
     * Test si l'utilisateur utilise un navigateur sur mobile
     *
     * @return bool True si un navigateur mobile est détecté
     */
    public static function isMobile(): bool
    {
        $userAgent = 'none';
        if (isset($_SERVER["HTTP_USER_AGENT"])) {
            $userAgent = $_SERVER["HTTP_USER_AGENT"];
        }
        $result = false;
        if (stristr($userAgent, "Android") ||
            strpos($userAgent, "iPod") ||
            strpos($userAgent, "iPhone") ||
            strpos($userAgent, "Mobile") ||
            strpos($userAgent, "WebOS") ||
            strpos($userAgent, "mobile") ||
            strpos($userAgent, "hp-tablet")) {
            $result = true;
        }
        return $result;
    }
}