Page 1 of 1

Password Protected Page

Posted: Thu Jul 03, 2008 4:02 pm
by Ninjataktikz
Hi guys,
Hi guys I am trying to make a password protected page just testing it out on my local machine. I am still in the progress of learning php. But I am stuck right now. First of all this is the code that I am using.

I also made a text file with 6 login's and I am using this code to retrieve them
THIS IS THE PAGE THAT CHECKS IF THE LOGIN INFO IS CORRECT.

Code: Select all

<?php
    // Retrieving username and pass
    session_start();
    $u = $_POST["username"];
    $p = $_POST["password"];
    
    //declaring user and pass as global
    
    $_SESSION["u"]=$u;
    $_SESSION["p"]=$p;
    
    // choping so no spaces
    $x=chop($user_name[0]);
    $x=chop($user_name[1]);
    $x=chop($user_name[2]);
    $x=chop($user_name[3]);
    $x=chop($user_name[4]);
    $x=chop($user_name[5]);
    
    //gets the info from this textfile
    $user_name = file("login.txt");
    
    // checks if the login is correct
    
    $found=0;
    for ($x=0; $x<count($u_list); $x++)
    {
        if(($u==$u_list[$x]) && ($p==$p_list[$x]))
        {
                $found=1;
        }
    }
?>
 
This is the Main Form I made for the user to type in the username and password

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Password Protected Page</title>
</head>
<body onLoad="JavaScript&#058;document.form1.username.focus()">
<h1>Welcome to Secure Info Vault</h1>   
    <form method="post" action="check_login.php" name="form1">
        <p>USERNAME:<input type="text" name="username" /></p>
        <p>PASSWORD:<input type="password" name="password" /></p>
                    <input type="submit" name="login" value="Login" />
    </form>  
</body>
</html>
Problem I am having is when I enter the Username and password. It will then go to the check Login page and if it is correct it should take me to the MAIN page that I still have to make but I am having problem doing that. Please help me out on this.

Thank You

Gary

Re: Password Protected Page

Posted: Thu Jul 03, 2008 6:58 pm
by califdon
You need to study some PHP basics. You are trying to use variables and arrays before you initialize them with values. You are also limiting your script to 6 users when you could much more easily use a foreach loop. I recommend starting with a tutorial such as http://w3schools.com/php/