SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined index? - Wheres this suddenly come from?

    Hi guys

    I've had a spot of bother recently with my host. FTP has been unreachable randomly and the brown-outs are so bad that I decided to give up and move my site to my own WAMP server.

    Here's what I am using:
    Windows XP
    Apache 1.3 (Has some mods which v2 doesn't)
    PHP4
    Mysql4

    Now.. Can anyone tell me why php has decided to start throwing wobblies over almost EVERYTHING?

    This is the common message I'm getting:
    Notice: Undefined index: to in p:\turbozerv\www\test\modules\messages.php on line 33

    The line of code in question is this:
    Code:
    $Compose_To = $_HTTP['to'];
    Now mysteriously, if I then use my code tester page to run this code:
    Code:
    $_HTTP['to'] = 'tango';
    $Compose_To = $_HTTP['to'];
    print $Compose_To;
    It works!

    Apparently I've not got to test ALL variables first using the isset() function just in case its empty string, false bool, 0 integer etc.

    I've never had this problem with php4 previously, so whats happened?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You had your error reporting level at a lower setting in the previous configuration. Accessing an undefined index has always been a warning. You can turn down the error reporting if you don't want to see it, but you're warned for a reason -- you should know, or when you can't know, test that a variable is defined before using it.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm that makes sense!

    I've already started re-writing my code to test the vars now.. Thats the stupid thing isn't it about some servers... turn off the error reporting and fool you into thinking you're actually becoming a decent coder..

    I suppose in hindsight its probably a good thing all this has happened as its taught me a big lesson! Very frustrating though..

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In production, you want display_errors off. There's no good reason for a user to ever see a php generated error message.

    But, you should log errors to an error log so you can investigate.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •