A simple script - login isn't working
Posted: Mon Oct 22, 2007 4:54 pm
I whipped up this little script and I've looked over it many times, I can't figure out why its not working as intended.
Its a script to be used for logging in and editing a text file which is to be included by another page. But, after logging in its taking me back to the login form part even though it should have authenticated me and let me edit the file.
Its a script to be used for logging in and editing a text file which is to be included by another page. But, after logging in its taking me back to the login form part even though it should have authenticated me and let me edit the file.
Code: Select all
<?php session_start();
if ($_SESSION['auth'] != true)
{
exit('<form action="?a=login" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="Login" />
</form>');
}
if($_GET['a']=='login')
{
if($_POST['username']=='username' and $_POST['password']=='password')
{
$_SESSION['auth'] = true; header('Location: edit.php'); exit;
}
else
{
$_SESSION['auth'] = false; header('Location: edit.php'); exit;
}
}
elseif($_GET['a']=='logout')
{
session_destroy();
exit('You are now logged out.');
}
elseif($_GET['a']=='edit' and !empty($_POST['text']))
{
file_put_contents('file.txt',$_POST['text']); exit;
}
?>
<form action="?a=edit" method="post">
<textarea name="text" cols="6" rows="12" />
<input type="submit" value="Edit" />
</form>