$_REQUEST problem

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

    $_REQUEST problem

    This line of code make an "Undefined index" error on my PC, however it is
    okay on my friend's PC.
    Anyone has this experience?


    $somevar = $_REQUEST["name"];



  • kingofkolt

    #2
    Re: $_REQUEST problem

    "melty" <m@lty.com> wrote in message news:1090294263 .937002@hkpu01. ..[color=blue]
    > This line of code make an "Undefined index" error on my PC, however it is
    > okay on my friend's PC.
    > Anyone has this experience?
    >
    >
    > $somevar = $_REQUEST["name"];
    >
    >
    >[/color]

    Try accessing the page with a query string of "?name=foo" or sending a
    $_POST variable called "name"...


    Comment

    • John Unleaded Smith

      #3
      Re: $_REQUEST problem

      kingofkolt wrote:
      [color=blue]
      > "melty" <m@lty.com> wrote in message news:1090294263 .937002@hkpu01. ..
      >[color=green]
      >>This line of code make an "Undefined index" error on my PC, however it is
      >>okay on my friend's PC.
      >>Anyone has this experience?
      >>
      >>
      >>$somevar = $_REQUEST["name"];
      >>
      >>
      >>[/color]
      >
      >
      > Try accessing the page with a query string of "?name=foo" or sending a
      > $_POST variable called "name"...
      >[/color]

      A high level of error reporting will also cause PHP to print those
      messages/warnings.

      In php.ini;

      error_reporting = E_ALL & ~E_NOTICE

      should suffice.

      Comment

      • Gordon Burditt

        #4
        Re: $_REQUEST problem

        >This line of code make an "Undefined index" error on my PC, however it is[color=blue]
        >okay on my friend's PC.
        >Anyone has this experience?
        >
        >
        >$somevar = $_REQUEST["name"];[/color]

        My approach to this is: always use isset() on any variable you
        aren't absolutely sure is set before trying to use its value. You
        can NEVER be sure that a particular variable in $_GET, $_POST,
        $_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
        execution of your page. Consider any "undefined index" or "undefined
        variable" message to be a bug in your code.

        Also, use error_reporting (E_ALL) to make sure that if you use
        an uninitialized value, it gets reported.

        Gordon L. Burditt

        Comment

        • steve

          #5
          Re: Re: $_REQUEST problem

          "Gordon Burditt37" wrote:[color=blue][color=green]
          > >This line of code make an "Undefined index" error on my PC,[/color]
          > however it is[color=green]
          > >okay on my friend’s PC.
          > >Anyone has this experience?
          > >
          > >
          > >$somevar = $_REQUEST["name"];[/color]
          >
          > My approach to this is: always use isset() on any variable you
          > aren’t absolutely sure is set before trying to use its value.
          > You
          > can NEVER be sure that a particular variable in $_GET, $_POST,
          > $_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
          > execution of your page. Consider any "undefined index" or[/color]
          "undefined[color=blue]
          > variable" message to be a bug in your code.
          >
          > Also, use error_reporting (E_ALL) to make sure that if you use
          > an uninitialized value, it gets reported.
          >
          > Gordon L. Burditt</font>[/color]

          I second Gordon’s comment. Tight error reporting ensures that you
          catch some very pesky bugs- more work, more reward.

          If undefined is a valid value for any variable--in other works you
          don’t want to get any warnings, then use this function around your
          variable.
          $somevar = nullit($_REQUES T["name"]);

          Function nullit(&$varin) { //must pass by reference, so there is no
          explicit copying of var data
          //if undefined variable, then returns ’’ without doing an error,
          otherwise just returns the var.
          //this is done so we don’t get warning
          if (isset($varin)) {
          return ($varin);
          }
          else {
          return (’’);
          }
          }

          --
          http://www.dbForumz.com/ This article was posted by author's request
          Articles individually checked for conformance to usenet standards
          Topic URL: http://www.dbForumz.com/PHP-_REQUEST...ict131132.html
          Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578

          Comment

          • steve

            #6
            Re: Re: $_REQUEST problem

            "Gordon Burditt37" wrote:[color=blue][color=green]
            > >This line of code make an "Undefined index" error on my PC,[/color]
            > however it is[color=green]
            > >okay on my friend’s PC.
            > >Anyone has this experience?
            > >
            > >
            > >$somevar = $_REQUEST["name"];[/color]
            >
            > My approach to this is: always use isset() on any variable you
            > aren’t absolutely sure is set before trying to use its value.
            > You
            > can NEVER be sure that a particular variable in $_GET, $_POST,
            > $_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
            > execution of your page. Consider any "undefined index" or[/color]
            "undefined[color=blue]
            > variable" message to be a bug in your code.
            >
            > Also, use error_reporting (E_ALL) to make sure that if you use
            > an uninitialized value, it gets reported.
            >
            > Gordon L. Burditt</font>[/color]

            I second Gordon’s comment. Tight error reporting ensures that you
            catch some very pesky bugs- more work, more reward.

            If undefined is a valid value for any variable--in other works you
            don’t want to get any warnings, then use this function around your
            variable.
            $somevar = nullit($_REQUES T["name"]);

            Function nullit(&$varin) { //must pass by reference, so there is no
            explicit copying of var data
            //if undefined variable, then returns ’’ without doing an error,
            otherwise just returns the var.
            //this is done so we don’t get warning
            if (isset($varin)) {
            return ($varin);
            }
            else {
            return (’’);
            }
            }

            --
            http://www.dbForumz.com/ This article was posted by author's request
            Articles individually checked for conformance to usenet standards
            Topic URL: http://www.dbForumz.com/PHP-_REQUEST...ict131132.html
            Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578

            Comment

            • steve

              #7
              Re: Re: $_REQUEST problem

              "Gordon Burditt37" wrote:[color=blue][color=green]
              > >This line of code make an "Undefined index" error on my PC,[/color]
              > however it is[color=green]
              > >okay on my friend’s PC.
              > >Anyone has this experience?
              > >
              > >
              > >$somevar = $_REQUEST["name"];[/color]
              >
              > My approach to this is: always use isset() on any variable you
              > aren’t absolutely sure is set before trying to use its value.
              > You
              > can NEVER be sure that a particular variable in $_GET, $_POST,
              > $_REQUEST, $_COOKIE, $_SERVER, or $_SESSION is set at the start of
              > execution of your page. Consider any "undefined index" or[/color]
              "undefined[color=blue]
              > variable" message to be a bug in your code.
              >
              > Also, use error_reporting (E_ALL) to make sure that if you use
              > an uninitialized value, it gets reported.
              >
              > Gordon L. Burditt</font>[/color]

              I second Gordon’s comment. Tight error reporting ensures that you
              catch some very pesky bugs- more work, more reward.

              If undefined is a valid value for any variable--in other works you
              don’t want to get any warnings, then use this function around your
              variable.
              $somevar = nullit($_REQUES T["name"]);

              Function nullit(&$varin) { //must pass by reference, so there is no
              explicit copying of var data
              //if undefined variable, then returns ’’ without doing an error,
              otherwise just returns the var.
              //this is done so we don’t get warning
              if (isset($varin)) {
              return ($varin);
              }
              else {
              return (’’);
              }
              }

              --
              http://www.dbForumz.com/ This article was posted by author's request
              Articles individually checked for conformance to usenet standards
              Topic URL: http://www.dbForumz.com/PHP-_REQUEST...ict131132.html
              Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=437578

              Comment

              • Michael Fesser

                #8
                Re: $_REQUEST problem

                .oO(John Unleaded Smith)
                [color=blue]
                >A high level of error reporting will also cause PHP to print those
                >messages/warnings.
                >
                >In php.ini;
                >
                >error_reportin g = E_ALL & ~E_NOTICE
                >
                >should suffice.[/color]

                Not on a development system. Better fix the problem instead of turning
                off notices.

                $somevar = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';

                Even if it's "only" a notice, it's possible that the code does not
                exactly do what you expect it to do. Fixing notices prevents some hard
                to find bugs.

                Micha

                Comment

                Working...