/*
@author Sidewind3r
*/
/*Copy and paste this code and name the file Login.html*/
<html>
<form action="Login.php" method="POST">
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br />
<input type="submit" value="Login">
</form>
</html>
/*copy and paste this code and name the file Login.php*/
<?php
/************
**Login.php**
*************/
$User = stripslashes(strip_tags($_POST['user']));
$Pass = stripslashes(strip_tags($_POST['pass']));
$file = file_get_contents("log.txt");
if ($User === null){
die("Please enter a Username");
} if ($Pass === null){
die ("Please enter a Password");
}
$pos = strpos($file, "Username: ".$User." Password: ".$Pass);
if ($pos === false){
die("Wrong username or Password");
} else {
echo "You have been logged in...";
}
?>
/*copy and paste this code and name the file Register.html*/
/****************
**Register.html**
*****************/
<html>
<form action="Register.php" method="POST">
Username: <input type="text" name="username"><br />
Password: <input type="password" name="password"><br />
<input type="submit" value="Register">
</form>
</html>
/*copy and paste this code and name the file Register.php*/
<?php
/****************
**Register.php**
*****************/
$Username = stripslashes(strip_tags($_POST['username']));
$Password = stripslashes(strip_tags($_POST['password']));
$file = file_get_contents("log.txt");
if ($Username === null){
die("Please enter a Username");
}
if ($Password === null){
die ("Please enter a Password");
}
if (strpos($file,"Username: ".$Username)){
die ("That username is already in use");
}
$room_file=file("log.txt",FILE_IGNORE_NEW_LINES);
$room_file[]="Username: ".$Username." Password: ".$Password;
if (count($room_file)>20)$room_file=array_slice($room_file,1);
$file_save=fopen("log.txt","w+");
flock($file_save,LOCK_EX);
for($line=0;$line<count($room_file);$line++){
fputs($file_save,$room_file[$line]."\n");
};
flock($file_save,LOCK_UN);
fclose($file_save);
echo "You have been registered. Please <a href='Login.html'>login</a>";
exit();
?>