Well i got my login system
login.php
Code: Select all
<?php
<html>
<head>
<title>Log-in</title>
</head>
<body>
<?
#User Variables
$datafile="/home/username/data.txt";
#End User Variales
#If the call for the script is to log them in, DO IT!
if($action == "login"):
#This makes sure all fields are filled out.
if((!$username)or(!$password)){
#If there is one missing, send them to the error.
error_message("One or more required fields were left blank!", $username, $password);
}
#Open the datafile and login the user.
$file=file($datafile);
while(list(,$value)=each($file)){
list($fname,$femail,$furl,$fuser,$fpass,$blank)=split( "\|", $value);
if($username==$fuser && $password==$fpass){
echo "<H3>Log-in Success!</H3>";
echo "<FORM action='$PHP_SELF?action=change' method='post'>";
echo "<P>Name: <INPUT type='text' name='name' value='$fname'>";
echo "<P>E-mail Address: <INPUT type='text' name='email' value='$femail'>";
echo "<P>Website Address: <INPUT type='text' name='url' value='$furl'>";
echo "<P>Password: <INPUT type='text' name='newpass' value='$fpass'>";
echo "<P>Current Username: <INPUT type='text' name='username' value='$username'>";
echo "<P>Current Password: <INPUT type='text' name='password' value='$password'>";
echo "<P><INPUT type='submit' value='Change'>";
echo "</FORM>";
$logink="1";
}
}
if($logink==""):
error_message("Login failed, bad username/password", $username, $password);
endif;
elseif($action=="change"):
#This makes sure all fields are filled out.
if((!$name)or(!$email)or(!$url)or(!$username)or(!$password)){
#If there is one missing, send them to the error.
error_message("One or more required fields were left blank! Please re-login.", $username, $password);
}
#Open the datafile and login the user.
$file=file($datafile);
while(list(,$value)=each($file)){
list($fname,$femail,$furl,$fuser,$fpass)=split( "\|", $value);
if($username==$fuser && $password==$fpass){
$oldword="$fname|$femail|$furl|$fuser|$fpass|";
$newword="$name|$email|$url|$username|$newpass|";
$fp = fopen($datafile, "r");
$data = fread($fp, filesize($datafile));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($datafile,"w");
fwrite($fp,$newdata) or die ("error writing");
fclose($fp);
$succ = "1";
echo "Everything was changed successfully! <A HREF="$PHP_SELF?action=login&username=$username&password=$newpass">Edit Again</A>";
}
}
if(!$succ):
error_message("Login failed, bad username/password", $username, $password);
endif;
else:?>
<FORM action="<?$PHP_SELF;?>?action=login" method="post">
<P>Username: <INPUT type="text" name="username">
<P>Password: <INPUT type="password" name="password">
<P><INPUT type="submit" value="Log-in">
</FORM>
<?endif;
function error_message($message, $username, $password){?>
<H3><?echo $message;?></H3>
<FORM action="<?$PHP_SELF;?>" method="post">
<P>Username: <INPUT type="text" name="username" value="<?echo $username;?>">
<P>Password: <INPUT type="password" name="password" value="<?echo $password;?>">
<P><INPUT type="submit" value="Log-in">
</FORM>
<?exit;
}?>
</body>
</html>
?>Code: Select all
<?php
<html>
<head>
<title>Signup</title>
</head>
<body>
<?
#User Variables
$datafile="/home2/BigE/data.txt";
#End User Variales
#If the action is to sign them up, do it!
if($action == "signup"):
#This makes sure all fields are filled out.
if((!$name)or(!$email)or(!$url)or(!$username)or(!$password)){
#If there is one missing, send them to the error.
error_message("One or more required fields were left blank!", $name, $email, $url, $username, $password);
}
#Open the datafile and make sure the user doesn't allready exist.
$file=file($datafile);
while(list(,$value)=each($file)){
list($fname,$femail,$furl,$fuser,$fpass,$blank)=split( "\|", $value);
if($username==$fuser){
#If the username is allready in user, error time.
error_message("Username is allready in use by someone else.", $name, $email, $url, $username, $password);
}
}
#If the username isn't in use, make it in use.
$fp=fopen($datafile,"a");
fwrite($fp,"$name|$email|$url|$username|$password|\n");
fclose($fp);
#Now we notify the person that they have signed up successfully.
?>
<H3>Success!</H3>
<P>Your information was successfully added into our database. Thank you for signing up.<BR>
You may now login using the username: <?echo $username;?> and password: <?echo $password;?> at<BR>
the <A HREF="login.phtml">Login</A> page.
<?
#If the action is for anything else, show this.
else:?>
<FORM action="<?echo $PHP_SELF;?>?action=signup" method="post">
<P>Name: <INPUT type="text" name="name">
<P>E-mail Address: <INPUT type="text" name="email">
<P>Website Address: <INPUT type="text" name="url">
<P>Desired Username: <INPUT type="text" name="username">
<P>Password: <INPUT type="password" name="password">
<P><INPUT type="submit" value="Sign-up">
</FORM>
<?endif;
function error_message($message, $name, $email, $url, $username, $password){?>
<H3><?echo $message;?></H3>
<FORM action="<?echo $PHP_SELF;?>?action=signup" method="post">
<P>Name: <INPUT type="text" name="name" value="<?echo $name;?>">
<P>E-mail Address: <INPUT type="text" name="email" value="<?echo $email;?>">
<P>Website Address: <INPUT type="text" name="url" value="<?echo $url;?>">
<P>Desired Username: <INPUT type="text" name="username" value="<?echo $username;?>">
<P>Password: <INPUT type="password" name="password" value="<?echo $password;?>">
<P><INPUT type="submit" value="Sign-up">
</FORM>
<?exit;
}?>
</body>
</html>
?>