Professional Web Applications Themes

Log in page - PHP Development

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("correctdir/album.htm"); } else { // Wrong pwd echo("../somdir/default.htm"); } else { // wrong user echo("../otherdir/default.htm"); } } } ?> ...

  1. #1

    Default 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("correctdir/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
    tlakso Guest

  2. #2

    Default Re: Log in page

    tlakso wrote:
    > 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...)
    > Can't get it to work. Any good idea to resolve this? Any other more
    > brilliant solution instead of this?
    You could do this:

    if (!isset($_SESSION["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

    Dalibor Karlovic Guest

  3. #3

    Default Re: Log in page

    [email]tlaksohotmail.com[/email] (tlakso) wrote in message news:<85ae0955.0308111523.7c97f34dposting.google. com>...
    > Hi,
    >
    > trying to create a simple login page using php and a post form.
    Certainly you have to learn PHP. Buy some good books or Google
    for PHP articles.... I'll try to pointout your mistakes...
    >
    > 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;
    for what???
    > if( strcmp($_POST[$userfield],"user") == 0 ) {
    Try $_POST['userfield']

    >
    > if( strcmp($_POST[$pwdfield],"pwd") == 0 ) {
    > // Correct user
    > echo("correctdir/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?

    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
    R. Rajesh Jeba Anbiah Guest

  4. #4

    Default Re: Log in page

    [email]tlaksohotmail.com[/email] (tlakso) wrote in message news:<85ae0955.0308120544.24fa89e6posting.google. com>...
    >
    > 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\lib\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?
    It's because, you're trying to get the values before POST.
    > > > <form name="form1" method="post" action="<?php check_user();?>">
    > >
    > > ^^^^^^^^^^^^^^^^^^^^^
    >
    > What do you mean? Is it not possible to call this function there?

    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
    R. Rajesh Jeba Anbiah Guest

Similar Threads

  1. Trouble loading administrator/index.cfm page--i am askedto save the page
    By rajinibesttest in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: September 22nd, 06:19 AM
  2. Replies: 1
    Last Post: April 22nd, 11:28 AM
  3. Replies: 1
    Last Post: September 5th, 10:09 AM
  4. Replies: 1
    Last Post: August 8th, 03:05 PM
  5. Replies: 0
    Last Post: July 5th, 02:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139