Forum Moderators: coopster

Message Too Old, No Replies

I need help with this php code

         

Altec88

1:23 am on Feb 21, 2006 (gmt 0)

10+ Year Member



Ok, I'm trying to make a simple username,password system, and I need to know where the { } marks go. This is my first time with php. Here is the code:

<?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.

phparion

4:13 am on Feb 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well, {} are used to make blocks of codes specially when you use Loops or Conditions let me give you a simple example,

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?

omoutop

7:57 am on Feb 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i believe the correct code is like this :

<?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();
}
}
?>