Undefined index: REQUEST_METHOD

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bandit

    Undefined index: REQUEST_METHOD

    Hi there,
    I have installed a search engine on one of my websites - it had a few
    bugs in it, I got all but one out of the script.

    The results page works, but it displays this error on the top of the page:

    Notice: Undefined index: REQUEST_METHOD in \www\search\lib s\utils.php on
    line 409

    I have enclosed the code it refers to below. I am an amateur when it comes
    to PHP, and would appreciate any help. Thanks

    Line 409 is this first line.

    $retVal = $GLOBALS[$envVar];
    if (strlen($retVal ) < 1) {
    $retVal = getenv($envVar) ;
    if (strlen($retVal ) < 1) {
    $retVal = $HTTP_ENV_VARS[$envVar];
    if (strlen($retVal ) < 1) {
    $retVal = $HTTP_SERVER_VA RS[$envVar];
    }
    }

    Bandit


  • Chung Leong

    #2
    Re: Undefined index: REQUEST_METHOD

    Use @ to suppress the notice.

    $retVal = @$GLOBALS[$envVar];

    Or lower your error_reporting level.

    Uzytkownik "Bandit" <Info@Bar-Guide.ca> napisal w wiadomosci
    news:ra4Lb.1998 33$PD3.5927597@ nnrp1.uunet.ca. ..[color=blue]
    > Hi there,
    > I have installed a search engine on one of my websites - it had a few
    > bugs in it, I got all but one out of the script.
    >
    > The results page works, but it displays this error on the top of the page:
    >
    > Notice: Undefined index: REQUEST_METHOD in \www\search\lib s\utils.php on
    > line 409
    >
    > I have enclosed the code it refers to below. I am an amateur when it[/color]
    comes[color=blue]
    > to PHP, and would appreciate any help. Thanks
    >
    > Line 409 is this first line.
    >
    > $retVal = $GLOBALS[$envVar];
    > if (strlen($retVal ) < 1) {
    > $retVal = getenv($envVar) ;
    > if (strlen($retVal ) < 1) {
    > $retVal = $HTTP_ENV_VARS[$envVar];
    > if (strlen($retVal ) < 1) {
    > $retVal = $HTTP_SERVER_VA RS[$envVar];
    > }
    > }
    >
    > Bandit
    >
    >[/color]


    Comment

    • Daniel Tryba

      #3
      Re: Undefined index: REQUEST_METHOD

      Chung Leong <chernyshevsky@ hotmail.com> wrote:[color=blue]
      > Use @ to suppress the notice.
      >
      > $retVal = @$GLOBALS[$envVar];
      >
      > Or lower your error_reporting level.[/color]

      Noooooooooooooo . The correct answer is to write better code.
      [color=blue][color=green]
      >> $retVal = $GLOBALS[$envVar];
      >> if (strlen($retVal ) < 1) {
      >> $retVal = getenv($envVar) ;
      >> if (strlen($retVal ) < 1) {
      >> $retVal = $HTTP_ENV_VARS[$envVar];
      >> if (strlen($retVal ) < 1) {
      >> $retVal = $HTTP_SERVER_VA RS[$envVar];
      >> }
      >> }[/color][/color]

      There are no checks if the index does exist in the array... The
      nonexisting key is accessed directly...

      if(array_key_ex ists($envVar,$G LOBALS))
      {
      $retVal=$GLOBAL S[$envVar];
      }
      elseif(array_ke y_exists($envVa r,$_ENV))
      {
      ...
      }
      else
      {
      ...
      }

      --

      Daniel Tryba

      Comment

      • Tim Van Wassenhove

        #4
        Re: Undefined index: REQUEST_METHOD

        On 2004-01-08, Daniel Tryba <news_comp.lang .php@canopus.nl > wrote:
        [color=blue]
        > There are no checks if the index does exist in the array... The
        > nonexisting key is accessed directly...
        >
        > if(array_key_ex ists($envVar,$G LOBALS))
        > {
        > $retVal=$GLOBAL S[$envVar];
        > }[/color]

        As i've found array_key_exist s the most elegant way, isset is faster.


        --

        Comment

        • Tim Van Wassenhove

          #5
          Re: Undefined index: REQUEST_METHOD

          On 2004-01-08, Bandit <Info@Bar-Guide.ca> wrote:

          This is the 3th group i see your post.

          Really time to lookup a usenette introduction that tells you about
          multiposting and crossposting.

          --

          Comment

          • Daniel Tryba

            #6
            Re: Undefined index: REQUEST_METHOD

            Tim Van Wassenhove <euki@pi.be> wrote:[color=blue][color=green]
            >> There are no checks if the index does exist in the array... The
            >> nonexisting key is accessed directly...
            >>
            >> if(array_key_ex ists($envVar,$G LOBALS))
            >> {
            >> $retVal=$GLOBAL S[$envVar];
            >> }[/color]
            >
            > As i've found array_key_exist s the most elegant way, isset is faster.[/color]

            But array_key_exist s has added value: it will barf when the haystack isn't
            an array. IMHO that's more important than a few us.

            --

            Daniel Tryba

            Comment

            • Chung Leong

              #7
              Re: Undefined index: REQUEST_METHOD

              Doing more when less will suffice is vain.

              Uzytkownik "Daniel Tryba" <news_comp.lang .php@canopus.nl > napisal w
              wiadomosci news:btj4qr$j0v $2@news.tue.nl. ..[color=blue]
              > Chung Leong <chernyshevsky@ hotmail.com> wrote:[color=green]
              > > Use @ to suppress the notice.
              > >
              > > $retVal = @$GLOBALS[$envVar];
              > >
              > > Or lower your error_reporting level.[/color]
              >
              > Noooooooooooooo . The correct answer is to write better code.
              >[color=green][color=darkred]
              > >> $retVal = $GLOBALS[$envVar];
              > >> if (strlen($retVal ) < 1) {
              > >> $retVal = getenv($envVar) ;
              > >> if (strlen($retVal ) < 1) {
              > >> $retVal = $HTTP_ENV_VARS[$envVar];
              > >> if (strlen($retVal ) < 1) {
              > >> $retVal = $HTTP_SERVER_VA RS[$envVar];
              > >> }
              > >> }[/color][/color]
              >
              > There are no checks if the index does exist in the array... The
              > nonexisting key is accessed directly...
              >
              > if(array_key_ex ists($envVar,$G LOBALS))
              > {
              > $retVal=$GLOBAL S[$envVar];
              > }
              > elseif(array_ke y_exists($envVa r,$_ENV))
              > {
              > ...
              > }
              > else
              > {
              > ...
              > }
              >
              > --
              >
              > Daniel Tryba
              >[/color]


              Comment

              Working...