You are here

protected function TfaTrustedBrowser::getAgent in Two-factor Authentication (TFA) 8

Get simplified browser name from user agent.

Parameters

string $name: Default browser name.

Return value

string Simplified browser name.

5 calls to TfaTrustedBrowser::getAgent()
TfaTrustedBrowser::finalize in src/Plugin/TfaLogin/TfaTrustedBrowser.php
Finalize the browser setup.
TfaTrustedBrowser::setTrusted in src/Plugin/TfaLogin/TfaTrustedBrowser.php
Store browser value and issue cookie for user.
TfaTrustedBrowser::submitForm in src/Plugin/TfaLogin/TfaTrustedBrowser.php
Submit form.
TfaTrustedBrowserSetup::getSetupForm in src/Plugin/TfaSetup/TfaTrustedBrowserSetup.php
Get the setup form for the validation method.
TfaTrustedBrowserSetup::submitSetupForm in src/Plugin/TfaSetup/TfaTrustedBrowserSetup.php
Submit the setup form.

File

src/Plugin/TfaLogin/TfaTrustedBrowser.php, line 234

Class

TfaTrustedBrowser
Trusted browser validation class.

Namespace

Drupal\tfa\Plugin\TfaLogin

Code

protected function getAgent($name = '') {
  if (isset($_SERVER['HTTP_USER_AGENT'])) {

    // Match popular user agents.
    $agent = $_SERVER['HTTP_USER_AGENT'];
    if (preg_match("/like\\sGecko\\)\\sChrome\\//", $agent)) {
      $name = 'Chrome';
    }
    elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) {
      $name = 'Firefox';
    }
    elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
      $name = 'Internet Explorer';
    }
    elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {
      $name = 'Safari';
    }
    else {

      // Otherwise filter agent and truncate to column size.
      $name = substr($agent, 0, 255);
    }
  }
  return $name;
}