Varifying Forms Text Data Help Needed

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

    Varifying Forms Text Data Help Needed

    I bought the PHP and MySQL For Dummies book and I'm having trouble
    understanding how I use PHP to verify and check forms input text data
    - the book shows snippets of code so I know how to do the actual check
    but I don't understand what web page the php checking code should go
    into?

    For example, I have a simple login web page (username and password)
    and then it calls my mainmenu php web page - I want to make a check
    that a username was actually typed in *before* calling the mainmenu
    php page - I also know that I can do this check using javascript but
    I'd like to stay in php if I can - how can I make the check and stay
    on this login form before calling the mainmenu page?

    Thanks...

  • Ian.H [dS]

    #2
    Re: Varifying Forms Text Data Help Needed

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
    Freshour <ralph@primemai l.com> amazingly managed to produce the
    following with their Etch-A-Sketch:
    [color=blue]
    > I bought the PHP and MySQL For Dummies book and I'm having trouble
    > understanding how I use PHP to verify and check forms input text
    > data - the book shows snippets of code so I know how to do the
    > actual check but I don't understand what web page the php checking
    > code should go into?
    >
    > For example, I have a simple login web page (username and password)
    > and then it calls my mainmenu php web page - I want to make a check
    > that a username was actually typed in *before* calling the mainmenu
    > php page - I also know that I can do this check using javascript
    > but I'd like to stay in php if I can - how can I make the check and
    > stay on this login form before calling the mainmenu page?
    >
    > Thanks...[/color]



    Assuming you have 'username' and 'password' as your form text fields,
    and your method is POST:


    <?php
    if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
    @header('Locati on: http://' .
    $_SERVER['HTTP_HOST'] .
    '/login.php'
    );
    }

    if (!empty($_POST['password'])) {
    // do check for password match
    if (md5($_POST['password']) == $required_passw ord) {
    @header('Locati on: http://' .
    $_SERVER['HTTP_HOST'] .
    '/mainmenu.php'
    );
    } else {
    die('Invalid login');
    }
    ?>


    This isn't a coplete solution as you'll need to fill out the
    commented areas, but should do what you're after =)


    HTH.



    Regards,

    Ian

    -----BEGIN PGP SIGNATURE-----
    Version: PGP 8.0

    iQA/AwUBPwdr92fqtj2 51CDhEQJZ2ACfSx H6N4JBiaHnMl8wI JxL+4Whfy0AoIfT
    8wKHusl/p2M0a6HBdp01qcE b
    =g6N7
    -----END PGP SIGNATURE-----

    --
    Ian.H [Design & Development]
    digiServ Network - Web solutions
    www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
    Programming, Web design, development & hosting.

    Comment

    • Ralph Freshour

      #3
      Re: Varifying Forms Text Data Help Needed

      @header('Locati on: http://' .$_SERVER['HTTP_HOST'] .'/login.php'

      gives me an error:

      Parse error: parse error, unexpected T_CONSTANT_ENCA PSED_STRING

      The PHP Manual gives this syntax for header() but it gives a similar
      error:

      header("Locatio n:http://".$_SERVER['HTTP_HOST'].dirname($_SERV ER['PHP_SELF'])."/login.php");

      I gather this header function check will cause my login.php script
      re-display which is what I want when the user leaves it blank and
      still clicks on the submit button.

      Ralph

      On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
      <ian@WINDOZEdig iserv.net> wrote:
      [color=blue]
      >-----BEGIN PGP SIGNED MESSAGE-----
      >Hash: SHA1
      >
      >Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
      >Freshour <ralph@primemai l.com> amazingly managed to produce the
      >following with their Etch-A-Sketch:
      >[color=green]
      >> I bought the PHP and MySQL For Dummies book and I'm having trouble
      >> understanding how I use PHP to verify and check forms input text
      >> data - the book shows snippets of code so I know how to do the
      >> actual check but I don't understand what web page the php checking
      >> code should go into?
      >>
      >> For example, I have a simple login web page (username and password)
      >> and then it calls my mainmenu php web page - I want to make a check
      >> that a username was actually typed in *before* calling the mainmenu
      >> php page - I also know that I can do this check using javascript
      >> but I'd like to stay in php if I can - how can I make the check and
      >> stay on this login form before calling the mainmenu page?
      >>
      >> Thanks...[/color]
      >
      >
      >
      >Assuming you have 'username' and 'password' as your form text fields,
      >and your method is POST:
      >
      >
      ><?php
      > if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
      > @header('Locati on: http://' .
      > $_SERVER['HTTP_HOST'] .
      > '/login.php'
      > );
      > }
      >
      > if (!empty($_POST['password'])) {
      > // do check for password match
      > if (md5($_POST['password']) == $required_passw ord) {
      > @header('Locati on: http://' .
      > $_SERVER['HTTP_HOST'] .
      > '/mainmenu.php'
      > );
      > } else {
      > die('Invalid login');
      > }
      >?>
      >
      >
      >This isn't a coplete solution as you'll need to fill out the
      >commented areas, but should do what you're after =)
      >
      >
      >HTH.
      >
      >
      >
      >Regards,
      >
      > Ian
      >
      >-----BEGIN PGP SIGNATURE-----
      >Version: PGP 8.0
      >
      >iQA/AwUBPwdr92fqtj2 51CDhEQJZ2ACfSx H6N4JBiaHnMl8wI JxL+4Whfy0AoIfT
      >8wKHusl/p2M0a6HBdp01qcE b
      >=g6N7
      >-----END PGP SIGNATURE-----[/color]

      Comment

      • Steven

        #4
        Re: Varifying Forms Text Data Help Needed


        "Ralph Freshour" <ralph@primemai l.com> wrote in message
        news:7k0fgv8ah2 f0aobqheoftn6pj 4egbft33h@4ax.c om...[color=blue]
        > @header('Locati on: http://' .$_SERVER['HTTP_HOST'] .'/login.php'
        >
        > gives me an error:
        >
        > Parse error: parse error, unexpected T_CONSTANT_ENCA PSED_STRING
        >
        > The PHP Manual gives this syntax for header() but it gives a similar
        > error:
        >
        >[/color]
        header("Locatio n:http://".$_SERVER['HTTP_HOST'].dirname($_SERV ER['PHP_SELF']
        )."/login.php");[color=blue]
        >
        > I gather this header function check will cause my login.php script
        > re-display which is what I want when the user leaves it blank and
        > still clicks on the submit button.
        >
        > Ralph
        >
        > On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
        > <ian@WINDOZEdig iserv.net> wrote:
        >[color=green]
        > >-----BEGIN PGP SIGNED MESSAGE-----
        > >Hash: SHA1
        > >
        > >Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
        > >Freshour <ralph@primemai l.com> amazingly managed to produce the
        > >following with their Etch-A-Sketch:
        > >[color=darkred]
        > >> I bought the PHP and MySQL For Dummies book and I'm having trouble
        > >> understanding how I use PHP to verify and check forms input text
        > >> data - the book shows snippets of code so I know how to do the
        > >> actual check but I don't understand what web page the php checking
        > >> code should go into?
        > >>
        > >> For example, I have a simple login web page (username and password)
        > >> and then it calls my mainmenu php web page - I want to make a check
        > >> that a username was actually typed in *before* calling the mainmenu
        > >> php page - I also know that I can do this check using javascript
        > >> but I'd like to stay in php if I can - how can I make the check and
        > >> stay on this login form before calling the mainmenu page?
        > >>
        > >> Thanks...[/color]
        > >
        > >
        > >
        > >Assuming you have 'username' and 'password' as your form text fields,
        > >and your method is POST:
        > >
        > >
        > ><?php
        > > if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
        > > @header('Locati on: http://' .
        > > $_SERVER['HTTP_HOST'] .
        > > '/login.php'
        > > );
        > > }
        > >
        > > if (!empty($_POST['password'])) {
        > > // do check for password match
        > > if (md5($_POST['password']) == $required_passw ord) {
        > > @header('Locati on: http://' .
        > > $_SERVER['HTTP_HOST'] .
        > > '/mainmenu.php'
        > > );
        > > } else {
        > > die('Invalid login');
        > > }
        > >?>
        > >
        > >
        > >This isn't a coplete solution as you'll need to fill out the
        > >commented areas, but should do what you're after =)
        > >
        > >
        > >HTH.
        > >
        > >
        > >
        > >Regards,
        > >
        > > Ian
        > >
        > >-----BEGIN PGP SIGNATURE-----
        > >Version: PGP 8.0
        > >
        > >iQA/AwUBPwdr92fqtj2 51CDhEQJZ2ACfSx H6N4JBiaHnMl8wI JxL+4Whfy0AoIfT
        > >8wKHusl/p2M0a6HBdp01qcE b
        > >=g6N7
        > >-----END PGP SIGNATURE-----[/color]
        >[/color]

        Try to use double quote instead of single quote:
        $_SERVER["HTTP_HOST"]




        Comment

        • Ralph Freshour

          #5
          Re: Varifying Forms Text Data Help Needed

          What is the code flow with this header() function? When I inserted
          your suggested header code, the browser web page didn't do anything -
          nothing but the loading bar was moving across like it was trying to do
          something or was doing something - is this in an endless loop? I
          don't understand how this code is 'triggered' - if it is processed
          when the login.php script first loads, then username is always blank
          since the user hasn't filled it in yet - maybe another way of asking
          this question is when does this if statement with the header code
          execute? I have it at the top of my .php script.


          On Sun, 06 Jul 2003 03:29:30 GMT, "Steven" <xueming@comcas t.net>
          wrote:
          [color=blue]
          >
          >"Ralph Freshour" <ralph@primemai l.com> wrote in message
          >news:7k0fgv8ah 2f0aobqheoftn6p j4egbft33h@4ax. com...[color=green]
          >> @header('Locati on: http://' .$_SERVER['HTTP_HOST'] .'/login.php'
          >>
          >> gives me an error:
          >>
          >> Parse error: parse error, unexpected T_CONSTANT_ENCA PSED_STRING
          >>
          >> The PHP Manual gives this syntax for header() but it gives a similar
          >> error:
          >>
          >>[/color]
          >header("Locati on:http://".$_SERVER['HTTP_HOST'].dirname($_SERV ER['PHP_SELF']
          >)."/login.php");[color=green]
          >>
          >> I gather this header function check will cause my login.php script
          >> re-display which is what I want when the user leaves it blank and
          >> still clicks on the submit button.
          >>
          >> Ralph
          >>
          >> On Sun, 06 Jul 2003 00:23:21 GMT, "Ian.H [dS]"
          >> <ian@WINDOZEdig iserv.net> wrote:
          >>[color=darkred]
          >> >-----BEGIN PGP SIGNED MESSAGE-----
          >> >Hash: SHA1
          >> >
          >> >Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
          >> >Freshour <ralph@primemai l.com> amazingly managed to produce the
          >> >following with their Etch-A-Sketch:
          >> >
          >> >> I bought the PHP and MySQL For Dummies book and I'm having trouble
          >> >> understanding how I use PHP to verify and check forms input text
          >> >> data - the book shows snippets of code so I know how to do the
          >> >> actual check but I don't understand what web page the php checking
          >> >> code should go into?
          >> >>
          >> >> For example, I have a simple login web page (username and password)
          >> >> and then it calls my mainmenu php web page - I want to make a check
          >> >> that a username was actually typed in *before* calling the mainmenu
          >> >> php page - I also know that I can do this check using javascript
          >> >> but I'd like to stay in php if I can - how can I make the check and
          >> >> stay on this login form before calling the mainmenu page?
          >> >>
          >> >> Thanks...
          >> >
          >> >
          >> >
          >> >Assuming you have 'username' and 'password' as your form text fields,
          >> >and your method is POST:
          >> >
          >> >
          >> ><?php
          >> > if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
          >> > @header('Locati on: http://' .
          >> > $_SERVER['HTTP_HOST'] .
          >> > '/login.php'
          >> > );
          >> > }
          >> >
          >> > if (!empty($_POST['password'])) {
          >> > // do check for password match
          >> > if (md5($_POST['password']) == $required_passw ord) {
          >> > @header('Locati on: http://' .
          >> > $_SERVER['HTTP_HOST'] .
          >> > '/mainmenu.php'
          >> > );
          >> > } else {
          >> > die('Invalid login');
          >> > }
          >> >?>
          >> >
          >> >
          >> >This isn't a coplete solution as you'll need to fill out the
          >> >commented areas, but should do what you're after =)
          >> >
          >> >
          >> >HTH.
          >> >
          >> >
          >> >
          >> >Regards,
          >> >
          >> > Ian
          >> >
          >> >-----BEGIN PGP SIGNATURE-----
          >> >Version: PGP 8.0
          >> >
          >> >iQA/AwUBPwdr92fqtj2 51CDhEQJZ2ACfSx H6N4JBiaHnMl8wI JxL+4Whfy0AoIfT
          >> >8wKHusl/p2M0a6HBdp01qcE b
          >> >=g6N7
          >> >-----END PGP SIGNATURE-----[/color]
          >>[/color]
          >
          >Try to use double quote instead of single quote:
          >$_SERVER["HTTP_HOST"]
          >
          >
          >[/color]

          Comment

          Working...