Page 1 of 1
HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 5:12 am
by simonmlewis
Code: Select all
$ua = $_SERVER["HTTP_USER_AGENT"];
We use this to determine what the user is browsing with, but it's causing errors in our error log.
So is there a way to query it, IF the users browser or system allows it?
It seems a lot are from Bing searches.
Re: HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 6:40 am
by Celauran
What sort of errors are you encountering? If you're just getting undefined index notices, wrap it in isset()
Re: HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 7:15 am
by simonmlewis
[text][Fri Jun 12 03:45:29 2015] [error] [client 00.00.00.00] PHP Notice: Undefined index: HTTP_USER_AGENT in /var/www/vhosts/site.co.uk/httpdocs/index.php on line 236[/text]
Re: HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 7:49 am
by Celauran
isset() will fix that. You always want to use isset() on array indices that may not have been set.
Re: HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 7:53 am
by simonmlewis
Like this?
Code: Select all
$ua = (isset($_SERVER["HTTP_USER_AGENT"]);
And then perhaps assign $ua as NULL beforehand?
Re: HTTP_USER_AGENT: Error log problem
Posted: Fri Jun 12, 2015 7:54 am
by Celauran
Something like this
Code: Select all
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown user agent';