class UserAgentService (View source)

Service for safely handling and sanitizing User-Agent strings

This service provides methods to safely retrieve and sanitize User-Agent strings for logging purposes, preventing potential security issues such as log injection attacks.

Constants

private MAX_LENGTH

private DEFAULT_USER_AGENT

Methods

__construct(array $server)

No description

string
getUserAgent()

Get the User-Agent string safely sanitized for logging

string
getShortUserAgent(int $maxLength = 100)

Get a shortened version of the User-Agent string

string
getBrowserInfo()

Get browser name and version from User-Agent

bool
isBot()

Check if the request is from a bot/crawler

Details

__construct(array $server)

No description

Parameters

array $server

string getUserAgent()

Get the User-Agent string safely sanitized for logging

Return Value

string

Sanitized User-Agent string

string getShortUserAgent(int $maxLength = 100)

Get a shortened version of the User-Agent string

Parameters

int $maxLength

Maximum length for the shortened string

Return Value

string

Shortened and sanitized User-Agent string

string getBrowserInfo()

Get browser name and version from User-Agent

Return Value

string

Browser identification (e.g., "Chrome/120.0", "Firefox/121.0", "Unknown")

bool isBot()

Check if the request is from a bot/crawler

Return Value

bool

True if User-Agent appears to be a bot