First off I don't know what you want to use a .txt file for a database and not mysql, it's not as safe. http://www.db4free.net/index.php?sec...tent=d4f_apply that's where you can get free mysql.
You WILL need PHP for this.
The first file is the register file named register.php :
PHP Code:
<?php $user = $_POST['user'];
$pass = $_POST['pass'];
$pass1 = $_POST['pass1'];
if($user != '' && ($pass != '' && $pass == $pass1)){
$text = file('users.txt');
$text= array_reverse($text);
foreach($text as $line){
list($name,$code) = split('::', '$line');
if($user == $name){header('Location: login.php?msg=1');exit;}
}
$file = "users.txt";
$fe = fopen($file, 'a') or die("Can't open file for writing.");
$data = $user."::".md5($pass);
fwrite($fe, $data);
fclose($fe);
header('Location: login.php?msg=2');
}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Registration</title>
</head><body>
<form action="register.php" method="post"><fieldset><legend>User and Pass</legend><input type="text" name="user"><input type="password" name="pass">Confirm Password: <input type="password" name="pass1"><input type="submit" value="Register"></form>
</body></html>
This is the login file, login.php :
PHP Code:
<?php session_start();
$user = $_POST['user'];
$pass = $_POST['pass'];
$msg = $_GET['msg'];
if($user != '' && $pass != ''){
$text = file('users.txt');
$text= array_reverse($text);
foreach($text as $line){
list($name,$code) = split('::', $line);
if($user == $name && md5($pass) == $code){$_SESSION['user'] = $user; $_SESSION['pass'] = $pass; header('Location: index.php');exit;}
}
echo "Username or password bad, please try again.";
}
if($msg == 1){
echo 'Username taken please login if it\'s yours or try to <a href="register.php">register</a> again.';}
if($msg == 2){
echo "Registration successful, please login below.";}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Login</title>
</head><body>
<form action="register.php" method="post"><fieldset><legend>Login Form</legend><input type="text" name="user"><input type="password" name="pass"><input type="submit" value="Register"></form>
<p>Don't have a login? Get one now, <a href="register.php">register</a>.</p>
</body></html>
Lastly the way users.txt would look:
For example:
Code:
test::098f6bcd4621d373cade4e832627b4f6
Any page that you want to use the session on you'll have to have start with
PHP Code:
<?php session_start();
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Last edited by Arenlor; 02-27-2008 at 05:04 PM..
Reason: Corrected the code, again
|