0

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();
1
  • Type this in the second line and see what it gets you: var_dump($_REQUEST['thing']) Commented Aug 22, 2011 at 4:41

3 Answers 3

4

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

$thingvalue = empty($_REQUEST['thing']) ? '' : $_REQUEST['thing'];
Sign up to request clarification or add additional context in comments.

1 Comment

Once again, I'm blown away by this community! Thank you so much, Doug!
1

It is trying to reference the index thing inside the $_REQUEST superglobal. If someone is viewing that page directly and was not posted via a form or directed with a ?thing=foobar in the query string, PHP will show that notice. I'd recommend not using $_REQUEST as it checks both $_GET and $_POST which is not very secure/practical - then check if it is set, and if not, taking some failsave action:

try
{
    if(!isset($_POST['thing']))
    {
        throw new Exception('No direct access. Please use our <a href="http://www.mysite.com/contact">Contact form</a>');
    }
    else
    {
        $thingvalue = $_POST['thing'];
    }
}
catch(Exception $e)
{
    echo $e->getMessage();
    exit();
}

Comments

0

The issue is that you are trying to get the value of thing here $thingvalue = $_REQUEST['thing']; before checking if the value exists first.

try this first

if( !isset( $_REQUEST['thing']) )
{
  do something because its missing
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.