variable handling - new user problem

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

    variable handling - new user problem

    Hi all,
    I am a new php learner. I have Fecora Core 1 with apache2 and php
    installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
    I have the following problem with both:

    I have a simple form: 1 field
    I submit with action=get and the value is passed.
    When the form refreshes the variable will NOT show with
    echo $username;

    However if I set $username to a value explicityly it will print it.
    This suggests that the variable value is not being passed from form to
    form. Otherwise php seems to be working.

    All help and ideas appreciated.

    TIA

    Bob Hartung

  • Eric Bohlman

    #2
    Re: variable handling - new user problem

    Bob Hartung <rwhart@netexpr ess.net> wrote in
    news:bvpn4r$nn8 @library1.airne ws.net:
    [color=blue]
    > Hi all,
    > I am a new php learner. I have Fecora Core 1 with apache2 and php
    > installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
    > I have the following problem with both:
    >
    > I have a simple form: 1 field
    > I submit with action=get and the value is passed.
    > When the form refreshes the variable will NOT show with
    > echo $username;
    >
    > However if I set $username to a value explicityly it will print it.
    > This suggests that the variable value is not being passed from form to
    > form. Otherwise php seems to be working.[/color]

    Older versions of php would automatically create variable names from form
    fields. That, however, can create lots of security and maintainability
    problems, so current versions don't do it unless you explicitly enable the
    register_global s option in php.ini. The preferred way to retrieve values
    when using the GET method is $_GET['username'] (if you had been using the
    POST method it would have been, surprise surprise, $_POST['username']).

    Many books and tutorials, especially if they're more than a few years old,
    assume that register_global s is turned on. I'd advise *not* turning it on
    at this stage in your learning, in order to avoid developing bad habits.

    Comment

    • Bob Hartung

      #3
      Re: variable handling - new user problem

      Eric
      Thank you! I also found that $_REQUEST in place of $_GET works the
      same. I am sure there are some nuances to this and I'll get to that,
      but now I can fumble my way ahead.

      And yes, you were correct. I am using an old book on PHP while
      awaiting somethins that looks good for PHP5 to hit the streets.
      Thanks again,

      Bob
      Eric Bohlman wrote:[color=blue]
      > Bob Hartung <rwhart@netexpr ess.net> wrote in
      > news:bvpn4r$nn8 @library1.airne ws.net:
      >
      >[color=green]
      >>Hi all,
      >> I am a new php learner. I have Fecora Core 1 with apache2 and php
      >>installed on 1 pc and SuSE 9 with apache2 and php installed on a laptop.
      >> I have the following problem with both:
      >>
      >> I have a simple form: 1 field
      >> I submit with action=get and the value is passed.
      >> When the form refreshes the variable will NOT show with
      >> echo $username;
      >>
      >> However if I set $username to a value explicityly it will print it.
      >>This suggests that the variable value is not being passed from form to
      >>form. Otherwise php seems to be working.[/color]
      >
      >
      > Older versions of php would automatically create variable names from form
      > fields. That, however, can create lots of security and maintainability
      > problems, so current versions don't do it unless you explicitly enable the
      > register_global s option in php.ini. The preferred way to retrieve values
      > when using the GET method is $_GET['username'] (if you had been using the
      > POST method it would have been, surprise surprise, $_POST['username']).
      >
      > Many books and tutorials, especially if they're more than a few years old,
      > assume that register_global s is turned on. I'd advise *not* turning it on
      > at this stage in your learning, in order to avoid developing bad habits.[/color]

      Comment

      • Eric Bohlman

        #4
        Re: variable handling - new user problem

        Bob Hartung <rwhart@netexpr ess.net> wrote in
        news:bvprsu$p3q @library2.airne ws.net:
        [color=blue]
        > Eric
        > Thank you! I also found that $_REQUEST in place of $_GET works the
        > same. I am sure there are some nuances to this and I'll get to that,
        > but now I can fumble my way ahead.[/color]

        The potential problems there are that, first, there's a configuration
        directive (variables_orde r) that controls which of the Get, Post, and
        Cookie values are included in $_REQUEST, and this may be set differently
        from server to server. Second, if a cookie value has the same name as a
        form value, or if both GET and POST are being used simultaneously (e.g. a
        form with method POST and an action URL with fixed query parameters), one
        of the values will overwrite the other in $_REQUEST (which one wins is
        determined by variables_order ).

        So using $_REQUEST isn't as reliable as using $_POST, $_GET, and $_COOKIE
        because it's more vulnerable to influences beyond your control.

        Comment

        Working...