That script seems ok, but I changed a few things last time I posted. I'll explain why and maybe it will help. This isn't meant to be an attack on your code, but just a way it could be improved some:
PHP Code:
$fp = fopen('flat-file-data.txt','r');
$line = fgets($fp, 1024);
//I don't see any need to fopen/fgets, when you can just use file_get_contents().
//that also avoids any permission errors that would be encountered with fopen.
list ($passwordlvl1, $passwordlvl2, $passwordlvl3) = split ('\|', $line);
//list is fine, but what if there are more listed in the file?
//certainly you don't need to use an external file for 3 passwords
//using split is also a bit weird. explode() doesn't require regex, and "|" would be valid, no need for \|.
if($_SESSION['password']==$passwordlvl1){//password #1
}elseif($_SESSION['password']==$passwordlvl2){//password #2
}elseif($_SESSION['password']==$passwordlvl3){//password #3
}
//ok, this would work.
//however, I would store a "logged in" variable in the session, not the password
//if ($_POST['pass']=='pass1') { $_SESSION['loginlevel'] = 1; }
else
{
header("location: login.php"); //fine, but technically should be a full URL for some reason
}
Bookmarks