Professional Web Applications Themes

Unidentified Index Problem on some servers - PHP Development

I'm getting an error message "Unidentified Index" when reading posted variables from a form $x = $_POST['VariableName'] I know I can use 'isset()' to check them first, but I'm curious as to why this works on some servers and not others......... Most of the servers I run it on just ignore the problem and result in the variable being assigned empty. I've tries on 3 different installations: 1 Linux ( No Error message) 1 Windows XP ( No Error message ) 1 Windows 2000 ( Fails! ) Is it a php.ini setting? Regards, Neil...

  1. #1

    Default Unidentified Index Problem on some servers

    I'm getting an error message "Unidentified Index" when reading posted
    variables from a form

    $x = $_POST['VariableName']

    I know I can use 'isset()' to check them first, but I'm curious as to why
    this works on some servers and not others......... Most of the servers I run
    it on just ignore the problem and result in the variable being assigned
    empty.

    I've tries on 3 different installations:

    1 Linux ( No Error message)
    1 Windows XP ( No Error message )
    1 Windows 2000 ( Fails! )

    Is it a php.ini setting?

    Regards,
    Neil


    Neil Strong Guest

  2. #2

    Default Re: Unidentified Index Problem on some servers

    Neil Strong wrote:
    > I'm getting an error message "Unidentified Index" when reading posted
    > variables from a form
    >
    > $x = $_POST['VariableName']
    >
    > I know I can use 'isset()' to check them first, but I'm curious as to why
    > this works on some servers and not others......... Most of the servers I run
    > it on just ignore the problem and result in the variable being assigned
    > empty.
    >
    > I've tries on 3 different installations:
    >
    > 1 Linux ( No Error message)
    > 1 Windows XP ( No Error message )
    > 1 Windows 2000 ( Fails! )
    >
    > Is it a php.ini setting?
    from: [url]http://php.net/error_reporting[/url]

    It seems that using E_NOTICE (included with E_ALL) is the only way to get
    warnings about undefined variables. For example, if you type $soemthing
    when you mean $something, you may not get any message about it unless you
    use E_NOTICE level reporting.

    The problem is, at that level of reporting you also get notices about array
    indexes that have not been set. This means lots of warnings when using
    $_GET['formvariable'] and such. You can check isset($_GET['formvariable'])
    first, but that gets annoying, especially when it is redundant to stricter
    input validation you need to do anyway.

    The only solution I have found is to use set_error_handler() to register a
    custom error reporting function to report everything except where the error
    string starts with "Undefined index:". Then I call error_reporting(E_ALL).
    This seems to be the best compromise.

    function error_handler($errno, $errstr, $errfile, $errline, $errctx) {
    if ($errno == E_NOTICE && substr($errstr, 0, 17) == "Undefined index:
    ") return;
    echo "\nerror_handler:\n\terrno=$errno\n\terrstr=$errst r\n";
    echo "\terrfile=$errfile\n\terrline=$errline\n";
    if ($errno & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))
    die();
    }
    set_error_handler("error_handler");
    error_reporting(E_ALL);

    checks the others comments too...

    Regards

    --
    David

    david Guest

  3. #3

    Default Re: Unidentified Index Problem on some servers

    Turn down error reporting.
    You probably have it set WAY to high.
    Also make sure you don't have something like this in your script
    if(error)die;
    Oh yeah also for post variables I just like to use

    extract($_POST);

    make sure you don't try

    $x = extract($_POST);

    Otherwise = $x winds up just being null or 0 or 1 I think, depending on you version.

    extract assigns all of them automagically
    If thats to sloppy and full of holes for ya try this

    if($_POST['VariableName']){
    $x = $_POST['VariableName'];
    }

    "Neil Strong" <Neil_Strongnodomain.com> wrote in message news:<bnit2q$3vv$1visp.bt.co.uk>...
    > I'm getting an error message "Unidentified Index" when reading posted
    > variables from a form
    >
    > $x = $_POST['VariableName']
    >
    > I know I can use 'isset()' to check them first, but I'm curious as to why
    > this works on some servers and not others......... Most of the servers I run
    > it on just ignore the problem and result in the variable being assigned
    > empty.
    >
    > I've tries on 3 different installations:
    >
    > 1 Linux ( No Error message)
    > 1 Windows XP ( No Error message )
    > 1 Windows 2000 ( Fails! )
    >
    > Is it a php.ini setting?
    >
    > Regards,
    > Neil
    Steve Guest

  4. #4

    Default Re: Unidentified Index Problem on some servers

    Steve <gr82meetu78> wrote:
    > Turn down error reporting.
    > You probably have it set WAY to high.
    Error reporting _can't_ be to high :)
    > if($_POST['VariableName']){
    > $x = $_POST['VariableName'];
    > }
    This will generate a warning if the index doens't exist, since the code
    aboce tries to access the index.

    Correct example would be:

    if(array_key_exists('VariableName',$_POST))
    {
    $x=$_POST['VariableName'];
    }

    --

    Daniel Tryba

    Daniel Tryba Guest

  5. #5

    Default Re: Unidentified Index Problem on some servers

    Hi Steve!

    On 27 Oct 2003 20:07:44 -0800, [email]gr82meetu78[/email] (Steve) wrote:
    >Oops hehe, you're right, I stand corrected.
    >On the other hand, the site shouldn't die either way, and errors
    >should be reported to a log, not dumped to the screen for everyone to
    >see.
    >IMHO this is one of PHP greatest failings in it's default
    >configuration.
    >There is however a way to fix this in the php.ini file.
    Depends a bit, if you want the bugs now or the bugs later. I love
    error notices, because they tell me, when

    - I misplelled a variable, property etc.
    - Assumed wrongfully a variable is an array, a scalar etc.
    - I didn't check a case
    - I don't have an else part for an if.

    All this will lead to a bug sometime, because someone will use the
    script in a way I haven't though of.

    I have notices off of course on the production server, but develop a
    script, until it runs without notices.

    HTH, Jochen

    >
    >Also error reporting can be too high, a person doesn't nessecarily
    >need to know about every single "notice". And a script certainly
    >shouldn't die when encountering a notice, only an error. This is what
    >I'm reffering to when I mean having it set to high.
    >Sorry about the confusion.
    >
    >Daniel Tryba <news_comp.lang.phpcanopus.nl> wrote in message news:<bnjsab$gdc$1news.tue.nl>...
    >> Steve <gr82meetu78> wrote:
    >> > Turn down error reporting.
    >> > You probably have it set WAY to high.
    >>
    >> Error reporting _can't_ be to high :)
    >>
    >> > if($_POST['VariableName']){
    >> > $x = $_POST['VariableName'];
    >> > }
    >>
    >> This will generate a warning if the index doens't exist, since the code
    >> aboce tries to access the index.
    >>
    >> Correct example would be:
    >>
    >> if(array_key_exists('VariableName',$_POST))
    >> {
    >> $x=$_POST['VariableName'];
    >> }
    --
    Jochen Daum - CANS Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    [url]http://sourceforge.net/projects/phpdbedittk/[/url]
    Jochen Daum Guest

  6. #6

    Default Re: Unidentified Index Problem on some servers

    Oops hehe, you're right, I stand corrected.
    On the other hand, the site shouldn't die either way, and errors
    should be reported to a log, not dumped to the screen for everyone to
    see.
    IMHO this is one of PHP greatest failings in it's default
    configuration.
    There is however a way to fix this in the php.ini file.

    Also error reporting can be too high, a person doesn't nessecarily
    need to know about every single "notice". And a script certainly
    shouldn't die when encountering a notice, only an error. This is what
    I'm reffering to when I mean having it set to high.
    Sorry about the confusion.

    Daniel Tryba <news_comp.lang.phpcanopus.nl> wrote in message news:<bnjsab$gdc$1news.tue.nl>...
    > Steve <gr82meetu78> wrote:
    > > Turn down error reporting.
    > > You probably have it set WAY to high.
    >
    > Error reporting _can't_ be to high :)
    >
    > > if($_POST['VariableName']){
    > > $x = $_POST['VariableName'];
    > > }
    >
    > This will generate a warning if the index doens't exist, since the code
    > aboce tries to access the index.
    >
    > Correct example would be:
    >
    > if(array_key_exists('VariableName',$_POST))
    > {
    > $x=$_POST['VariableName'];
    > }
    Steve Guest

Similar Threads

  1. Frontend Web Servers connect to Coldfusion Servers
    By Trensic in forum Coldfusion Server Administration
    Replies: 2
    Last Post: December 13th, 04:20 PM
  2. Problem with CF dying when related servers under load
    By Josh Ozura in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 26th, 06:57 PM
  3. Is this a problem for CF servers??
    By Steve Grosz in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 27th, 06:03 PM
  4. Problem with HTTPS and Proxy Servers using Net Framework 1.1
    By dzc55g in forum ASP.NET Web Services
    Replies: 2
    Last Post: May 11th, 12:22 AM
  5. Replies: 4
    Last Post: September 19th, 01:46 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139