Results 1 to 2 of 2

Thread: user validation issue

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    29

    Unhappy user validation issue

    I'm new to PHP and web programming in general - so this may seem like a stupid question but here it is anyway:

    I'm trying to password protect an area of a site. The only page that needs to be protected though, is the main index page for the area (theoretically someone could get into the other pages behind it if they knew the URL, but i'm not worried about that because of the obscure names of the pages)

    I can get a password from the user, pass it to the index page, and it works great, however, when you browse passed the index page, and then click a link for 'back to index' it takes you to the login page again. Here is the code i'm using in the index page:

    <?
    session_start();
    $pagepwd = "julie0407";
    if(is_null($password)){
    $password = $_POST['password'];

    import_request_variables("p", "var");
    }
    if($password != $pagepwd)
    {
    header('Location: test1.php');
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>


    <a href="test3.php">Click for page 3</a><br>
    the password is <?= $password ?>


    </body>
    </html>


    and here is the code in the logon page:

    <?php
    session_start();
    session_register('password');
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>form test 1</title>
    </head>

    <body>
    <form action="test2.php" method="post">
    Password: <input type="password" name="password" /><br /><br />
    <input type="submit" name="login" />

    </form>
    </body>
    </html>

    for testing purposes, there's a third document:

    <? session_start() ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <p><a href="test2.php">Click for page 2</a><br>
    the password is <?= $password ?>
    </p>
    </body>
    </html>

  2. #2
    Addicted Member
    Join Date
    Jan 2006
    Posts
    247

    Re: user validation issue

    First of all, can you put all of your code inside the PHP tags? Thanks...

    Second of all, I believe the problem is reading if a password has been set or not. Try testing it using this command (I am a little rusty with PHP so I do not know if this will totally 100% work).

    PHP Code:
    <?php
    if(isset($_SESSION['password']) {
    echo 
    "Hello World!" ;
    }
    else {
    echo 
    "You are not logged in!";
    }
    isset() is a command that checks if something is set, you can also use this for cookies. If this is not working, try reffering to this page: http://www.php.net/manual/en/function.isset.php

    I think that'll work. Replace the code as needed.
    Last edited by Seraphino; Aug 14th, 2006 at 07:39 PM.



Posting Permissions

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



Click Here to Expand Forum to Full Width