Search code examples
phpapachenotice

PHP notice - Undefined index on index.php


I'm running into a server notice that doesn't seem to effect the loading of my pages but nonetheless creates a new entry in the error log every time a page is loaded... That error is: PHP Notice: Undefined index: thing in C:\File Location\htdocs\index.php on line 1

I'm not sure whether the problem is actually on the first line or on a subsequent line, so I included a modified version of the whole file. The weird thing for me is that there's an identical line of code on several other files and it doesn't raise an issue in them. Also, the value is correctly extracted and all is well, I just don't know what to change in order to avoid the notice.

$thingvalue = $_REQUEST['thing'];

include("mdetect.php");

  $iphoneTierHomePage = 'mobilemain.php';
  $iphoneTierMobilePage = 'mobilepage.php?thing=' . $thingvalue;
  $genericMobileDeviceHomePage = 'mobilemain.php';
  $genericMobileDeviceMobilePage = 'mobilepage.php?thing=' . $thingvalue;
  $line1 = define('WP_USE_THEMES', true);
  $line2 = require('./wp-blog-header.php');
  $desktopPage == $line1 + $line2;

  $uagent_obj = new uagent_info();

  function AutoRedirectToProperHomePage()
  {
  global $thingvalue, $uagent_obj, $iphoneTierHomePage, $genericMobileDeviceHomePage, $iphoneTierMobilePage, $genericMobileDeviceMobilePage, $desktopPage;

  if ($thingvalue == ''){

      if ($uagent_obj->isTierIphone == $uagent_obj->true) 
      header ('Location: '.$iphoneTierHomePage);

      else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true) 
      header ('Location: '.$genericMobileDeviceHomePage);

      else
      header ('Location: '.$desktopHomePage);
    }
    if ($thingvalue != ''){
        if ($uagent_obj->isTierIphone == $uagent_obj->true) 
        header ('Location: '.$iphoneTierMobilePage);

        else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true) 
        header ('Location: '.$genericMobileDeviceMobilePage);

        else
        header ('Location: '.$desktopPage);
    }
  }

AutoRedirectToProperHomePage();

Solution

  • It's referring to the array index for the first line in index.php: Try this:

    $thingvalue = empty($_REQUEST['thing']) ? '' : $_REQUEST['thing'];