EDIT: I am the administrator of several websites and when I turn debug on to track down a problem on one of the sites, the debug.log is cluttered with hundreds of lines of PHP notices each day about a PHP problem in a plugin. The repeated notices obscure the debug information I am looking for to fix an important problem. I tried contacting the author of the plugin through the plugin's support forum to get a fix so I can stop the buildup of the log but there are no responses to questions in the forum for the plugin.

What do I need to do to suppress or fix this undefined index error in the WordPress plugin so it stops adding hundreds of PHP notices in the debug.log when I have debug turned on?

The plugin has a function to check if the browser is mobile. Since switching to PHP 7, I started getting the following PHP Notice:

Undefined index: HTTP_ACCEPT in /plugins/dynamic-to-top/inc/dynamic-to-top-class.php on line 440

This notice was not generated with PHP 5.6 so I thought something had changed in PHP 7 for this line to generate that notice? The answer below says it is not a change in PHP 7 that generated the notice but a more thorough reporting method. The following is the line that is called out in the notice.

        if( preg_match( "/wap\.|\.wap/i", $_SERVER["HTTP_ACCEPT"] ) )
            return true;

I checked the PHP Manual and HTTP_ACCEPT is a correct element for $_SERVER.

The full function is

    function is_mobile() {

        if( isset( $_SERVER["HTTP_X_WAP_PROFILE"] ) )
            return true;

        if( preg_match( "/wap\.|\.wap/i", $_SERVER["HTTP_ACCEPT"] ) )
            return true;

        if( isset( $_SERVER["HTTP_USER_AGENT"] ) ) {
            $user_agents = array(
                "midp", "j2me", "iphone", "avantg", "docomo", "novarra", "palmos",
                "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/",
                "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi",
                "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC",
                "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC",
                "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover",
                "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal",
                "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto" );

            foreach( $user_agents as $user_string ) {
                if( preg_match( "/" . $user_string . "/i", $_SERVER["HTTP_USER_AGENT"] ) )
                    return true;

        do_action( 'mv_dynamic_to_top_check_mobile' );

        return false;

Why isn't it a defined index?

  • This question appears to be off-topic because it is about web development which is off-topic at Pro Webmasters. Web development questions may be asked at Stack Overflow but be sure to read their FAQ before posting to ensure your question meets their guidelines. In its current form, this question does not meet their guidelines as it would be a duplicate question. – John Conde Jan 17 '18 at 18:05
  • I don't understand how trying to declutter the debug.log is about web development. Perhaps I have a different concept of what it means to administer a website? – Cynthia A Lockley Jan 22 '18 at 19:58

HTTP_ACCEPT may well be the correct environment var name, but that header won't necessarily be set, which is the cause of the warning. This is not a difference between PHP 5.6 and PHP 7 but more a difference in PHP's error reporting setting (the default of which might have changed between versions).

Since the header may not be set, checking whether or not it is before performing the regular expression check will fix the warning:

if( isset($_SERVER["HTTP_ACCEPT"]) && preg_match( "/wap\.|\.wap/i", $_SERVER["HTTP_ACCEPT"] ) )
    return true;
  • Thank you. I added that to the top of the function. I hope that was the right place to add it--it is working. I am no longer getting the PHP notice. – Cynthia A Lockley Jan 22 '18 at 17:18
  • Oops. I spoke too soon. The notice has come back but pointing to a different line over and over again. How do I just suppress it? [22-Jan-2018 19:02:56 UTC] PHP Notice: Undefined index: HTTP_ACCEPT in /wp-content/plugins/dynamic-to-top/inc/dynamic-to-top-class.php on line 443 – Cynthia A Lockley Jan 22 '18 at 19:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.