Forum Moderators: coopster
<?php
$found=0;
$filefopen("members.dat", "r");
(!feof($file))
$line=fgets($file,255);
$line=chop($line);
$field=split("#",$line,6);
if($username==$field[0])
$found=1;
if(password!=$field[1])
print "<h2>Wrong Password</h2>";
die();
if($found==0)
{print "<h2>Username does not exist</h2>";
die();
?>
Thanks a ton! I don't understand these marks. This part is supposed to authenticate a user before displaying the page.
if Condition = true
start operation
do this
do that
dont forge to do this too
end operation
in php, you use { for start Operation and } for end operation. however please note that if your conidion based operation is just only line then no need to use {} but if its more than one line then you have to use {} to make block of codes..
let me give you example like,
if (username AND password = Matched) {
enter time and date in log table
display lastvisit time from log table
say welcome to user
redirect him to main page
}
i hope it will clear your concerns HOWEVER i have one concern if you can answer it,
what if i get to know that you place your 'members.dat' in directory www.yourdomain.com/secret/members.dat
and if i brows this directly, do you think i will be able to save it on my system? do you thin i can open this with text editor and can read the usernames and password?
<?php
$found=0;
$file = fopen("members.dat", "r");
if(!feof($file))
{
$line=fgets($file,255);
$line=chop($line);
$field=split("#",$line,6); if($username==$field[0]) $found=1;
if(password!=$field[1])
print "<h2>Wrong Password</h2>";
die();
if($found==0)
{
print "<h2>Username does not exist</h2>";
die();
}
}
?>