Plugin Author
AITpro
(@aitpro)
http://stackoverflow.com/questions/14130830/php-undefined-index-http-user-agent
The User-Agent header is optional. Firewalls may filter it or people may configure their clients to omit it. Simply check using isset() if it exists. Or even better, use !empty() as an empty header won’t be useful either:
The php error does not occur on my test site since my server has this global variable “set” by default.
http://stackoverflow.com/questions/16330496/php-notice-undefined-index-http-user-agent-in-line-2
The solution is to check if the variable is set with isset. We will add that additional conditional check in the next BPS version.
# BEGIN USERAGENT FILTER
if ( isset($_SERVER['HTTP_USER_AGENT']) && !preg_match('/BPSUserAgentPlaceHolder/', $_SERVER['HTTP_USER_AGENT']) ) {
# END USERAGENT FILTER
Plugin Author
AITpro
(@aitpro)
Hmm actually that may be a bad thing to do. We need to check if this negates checking and blocking empty user agent fields, which are used by spambots and hackerbots and need to be blocked. In theory, since this line of code only pertains to the User Agent filter then it will probably be ok to add. Testing is required before this will be added if everything is ok.
Plugin Author
AITpro
(@aitpro)
Also check your wp-config.php file to see if WP_DEBUG is turned on. WP_DEBUG should only be used during debugging and should be turned Off after you are done debugging.
Hi guys,
actually WP_DEBUG is on because I’m debugging and anyway I’m not using public file to print all sort of possible warnings. There are even some plugins that are conflicting or are bad coded and I want to keep the DEBUG on (but I’m not exposing this).
Plugin Author
AITpro
(@aitpro)
Ok once you are done debugging then turn debugging off. Debugging is not supposed to be/intended to be left turned on normally. Debugging will slow down your overall website performance. How much I do not know, but that is standard for all debugging/debuggers.
Plugin Author
AITpro
(@aitpro)
What will be done in BPS .52.7 is to suppress the php error with an @ symbol since this php error is insignificant.
# BEGIN USERAGENT FILTER
if ( @!preg_match('/BPSUserAgentPlaceHolder/', $_SERVER['HTTP_USER_AGENT']) ) {
# END USERAGENT FILTER
Plugin Author
AITpro
(@aitpro)
New code has been added to suppress this php error in BPS .52.7 – this thread has been resolved.
Thread Start Date: 10-2-2015
Thread Resolved/Current Date: 10-6-2015
Comments: New code has been added to suppress this php error in BPS .52.7