Log in page

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

    Log in page

    Hi,

    trying to create a simple login page using php and a post form.

    The following requirement holds,
    1. there should NOT be any DB.
    2. One user and one password is enough (yeah, said it was a simple
    one...)

    Tried with a function check_user() in a lib php-file, and a post form
    in the login page. Code as follow:

    <?php

    function check_user(){
    global $userfield, $pwdfield;

    if( strcmp($_POST[$userfield],"user") == 0 ) {

    if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
    // Correct user
    echo("correctdi r/album.htm");
    }
    else {
    // Wrong pwd
    echo("../somdir/default.htm");
    }
    else {
    // wrong user
    echo("../otherdir/default.htm");
    }
    }

    }
    ?>

    and the login page for is:
    <?PHP
    require('../somelib/login_lib.php') ;
    ?>

    ....
    <form name="form1" method="post" action="<?php check_user();?> ">
    <input type="text" name="userfield " >
    <input type="password" name="pwdfield" >
    <input type="submit" name="Log in" value="Log in">
    </form>

    ....

    Can't get it to work. Any good idea to resolve this? Any other more
    brilliant solution instead of this?

    br,
    Magnus
  • Dalibor Karlovic

    #2
    Re: Log in page

    tlakso wrote:
    [color=blue]
    > The following requirement holds,
    > 1. there should NOT be any DB.
    > 2. One user and one password is enough (yeah, said it was a simple
    > one...)[/color]
    [color=blue]
    > Can't get it to work. Any good idea to resolve this? Any other more
    > brilliant solution instead of this?[/color]

    You could do this:

    if (!isset($_SESSI ON["pasword"])){
    // generate a password, store it to above place and mail it to yourself
    } else {
    // output form/validate form when submited
    }

    --
    Dado

    The original point and click interface was a Smith & Wesson

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Log in page

      tlakso@hotmail. com (tlakso) wrote in message news:<85ae0955. 0308111523.7c97 f34d@posting.go ogle.com>...[color=blue]
      > Hi,
      >
      > trying to create a simple login page using php and a post form.[/color]

      Certainly you have to learn PHP. Buy some good books or Google
      for PHP articles.... I'll try to pointout your mistakes...
      [color=blue]
      >
      > The following requirement holds,
      > 1. there should NOT be any DB.
      > 2. One user and one password is enough (yeah, said it was a simple
      > one...)
      >
      > Tried with a function check_user() in a lib php-file, and a post form
      > in the login page. Code as follow:
      >
      > <?php
      >
      > function check_user(){
      > global $userfield, $pwdfield;[/color]

      for what???
      [color=blue]
      > if( strcmp($_POST[$userfield],"user") == 0 ) {[/color]

      Try $_POST['userfield']

      [color=blue]
      >
      > if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
      > // Correct user
      > echo("correctdi r/album.htm");
      > }
      > else {
      > // Wrong pwd
      > echo("../somdir/default.htm");
      > }
      > else {
      > // wrong user
      > echo("../otherdir/default.htm");
      > }
      > }
      >
      > }
      > ?>
      >
      > and the login page for is:
      > <?PHP
      > require('../somelib/login_lib.php') ;
      > ?>
      >
      > ...
      > <form name="form1" method="post" action="<?php check_user();?> ">[/color]

      ^^^^^^^^^^^^^^^ ^^^^^^
      [color=blue]
      > <input type="text" name="userfield " >
      > <input type="password" name="pwdfield" >
      > <input type="submit" name="Log in" value="Log in">
      > </form>
      >
      > ...
      >
      > Can't get it to work. Any good idea to resolve this? Any other more
      > brilliant solution instead of this?[/color]


      Basci debugging trick: Run your PHP code on a webserver and
      "view source" of the html page to verify.

      HTH,
      R. Rajesh Jeba Anbiah

      ---
      Email: rrjanbiah-at-Y!com

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: Log in page

        tlakso@hotmail. com (tlakso) wrote in message news:<85ae0955. 0308120544.24fa 89e6@posting.go ogle.com>...[color=blue]
        >
        > Tried this with $_POST['userfield'] in strcmp, but still get this:
        > "
        > You don't have permission to access /<br /><b>Notice</b>: Undefined
        > index: userfield in <b>f:\apache\li b\login_lib.php </b> on line
        > <b>11</b><br /> on this server.
        > "
        >
        > so, the userfield index is undefined. PHP version is 4.3.2 and apache
        > 1.3. Any clue?[/color]

        It's because, you're trying to get the values before POST.
        [color=blue][color=green][color=darkred]
        > > > <form name="form1" method="post" action="<?php check_user();?> ">[/color]
        > >
        > > ^^^^^^^^^^^^^^^ ^^^^^^[/color]
        >
        > What do you mean? Is it not possible to call this function there?[/color]


        You can call a function, but not like JS. Obviously you have to
        learn PHP.... If you know HTML, "view html source" of your PHP code.

        ---
        Email: rrjanbiah-at-Y!com

        Comment

        Working...