Forcefuly setting '$HTTP_GET_VARS'

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

    Forcefuly setting '$HTTP_GET_VARS'

    Hi,

    Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS

    $HTTP_GET_VARS['foo'] = 'bar'?
    If yes, why? and how can i pass value between one page and the other without
    using the url?

    Regards,

    Sims


  • Kevin Thorpe

    #2
    Re: Forcefuly setting '$HTTP_GET_VARS '

    > Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS[color=blue]
    >
    > $HTTP_GET_VARS['foo'] = 'bar'?
    > If yes, why? and how can i pass value between one page and the other without
    > using the url?[/color]

    Feel free to do that if you wish. It will only exist until the end of
    this script though.

    To pass variables between scripts you can do one of the following:
    1. Add them to the URL and pick from $HTTP_GET_VARS (now $_GET)
    2. Add them to a form and pick from $HTTP_POST_VARS (now $_POST)
    3. add them to $_SESSION[] which is probably the recommended way.

    Comment

    • Sims

      #3
      Re: Forcefuly setting '$HTTP_GET_VARS '

      [color=blue][color=green]
      > > Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS
      > >
      > > $HTTP_GET_VARS['foo'] = 'bar'?
      > > If yes, why? and how can i pass value between one page and the other[/color][/color]
      without[color=blue][color=green]
      > > using the url?[/color]
      >
      > Feel free to do that if you wish. It will only exist until the end of
      > this script though.[/color]

      Yes sorry that is what i should have said.
      if( !$HTTP_GET_VARS['foo'] ){
      $HTTP_GET_VARS['foo'] = 'bar';
      }
      ....

      it would make it easier for me to assume that $HTTP_GET_VARS['foo'] exists
      by forcefully setting it at the beginning of the script.
      There are many ways of doing it like

      $myscritval['foo'] = isset(
      $_GET['foo'])?$_GET['foo']:(isset($_POST['foo'])?$_POST['foo']:'bar';

      I was curious about the value of $HTTP_GET_VARS if it was bad practice to
      set that value.
      [color=blue]
      >
      > To pass variables between scripts you can do one of the following:
      > 1. Add them to the URL and pick from $HTTP_GET_VARS (now $_GET)
      > 2. Add them to a form and pick from $HTTP_POST_VARS (now $_POST)[/color]

      What is the minimum php version for $_GET and $POST? I was told to use the
      old version as it will not hurt my script, ( as long as i have global
      $HTTP_GET_VARS; in my functions).
      [color=blue]
      > 3. add them to $_SESSION[] which is probably the recommended way.[/color]

      Yes of course, that is another way. But i keep been told that there are
      times where the user can set his browser to make sessions useless.
      But i have never really looked into it really.

      Sims


      Comment

      • Kevin Thorpe

        #4
        Re: Forcefuly setting '$HTTP_GET_VARS '

        Sims wrote:
        [color=blue][color=green][color=darkred]
        >>>Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS[/color][/color][/color]
        [color=blue][color=green]
        >>Feel free to do that if you wish. It will only exist until the end of
        >>this script though.[/color]
        >
        >
        > Yes sorry that is what i should have said.
        > if( !$HTTP_GET_VARS['foo'] ){
        > $HTTP_GET_VARS['foo'] = 'bar';
        > }
        > ...
        >
        > it would make it easier for me to assume that $HTTP_GET_VARS['foo'] exists
        > by forcefully setting it at the beginning of the script.[/color]

        Absolutely fine. That's probably good practice, while you're at it you
        should check that the sent value is reasonable.
        [color=blue]
        > What is the minimum php version for $_GET and $POST? I was told to use the
        > old version as it will not hurt my script, ( as long as i have global
        > $HTTP_GET_VARS; in my functions).[/color]

        4.1.0 - you'll need to watch out though as later releases of php will do
        away with the old variables.[color=blue]
        >
        >[color=green]
        >>3. add them to $_SESSION[] which is probably the recommended way.[/color]
        >
        > Yes of course, that is another way. But i keep been told that there are
        > times where the user can set his browser to make sessions useless.
        > But i have never really looked into it really.[/color]

        Sessions are really aimed towards using cookies. If cookie support is
        turned off then they don't work properly. There is a php.ini setting to
        transparently test if cookies are available and default to modifying all
        links to add the session id. It doesn't look pretty if cookies are off
        though.

        Comment

        • Markus Ernst

          #5
          Re: Forcefuly setting '$HTTP_GET_VARS '

          "Kevin Thorpe" <kevin@pricetra k.com> schrieb im Newsbeitrag
          news:405099da$0 $1124$afc38c87@ news.easynet.co .uk...[color=blue]
          > Sims wrote:
          >[color=green][color=darkred]
          > >>>Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS[/color][/color]
          >[color=green][color=darkred]
          > >>Feel free to do that if you wish. It will only exist until the end of
          > >>this script though.[/color]
          > >
          > >
          > > Yes sorry that is what i should have said.
          > > if( !$HTTP_GET_VARS['foo'] ){
          > > $HTTP_GET_VARS['foo'] = 'bar';
          > > }
          > > ...
          > >
          > > it would make it easier for me to assume that $HTTP_GET_VARS['foo'][/color][/color]
          exists[color=blue][color=green]
          > > by forcefully setting it at the beginning of the script.[/color]
          >
          > Absolutely fine. That's probably good practice, while you're at it you
          > should check that the sent value is reasonable.[/color]

          It seems wrong to me to create a variable that looks like a get variable but
          is none. Why not:

          if(isset($_GET['foo'])) {
          $foo = $_GET['foo'];
          }
          else {
          $foo = "bar";
          }

          If you extract all your request variables like that before processing them
          you have a transparent code. (If $foo can be transmitted with either get or
          post, just check for $_REQUEST['foo']). Also it is easier to write $foo than
          $_GET['foo'] or even $HTTP_GET_VARS['foo'] all the time.

          Imagine your script is 400 lines long, and anywhere your above code appears.
          In 2 years you have to make a modification, it will take you an hour to
          figure out why there is a value for a field that you did not submit!

          HTH
          Markus


          Comment

          Working...