REALLY simple login?
Posted: Wed Apr 19, 2006 10:37 am
I want a really simple login thing, that, all it does is say, the file logfile.txt cant be accessed unless you login. I dont even care if the password is in the code!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$username = 'John';
$password = 'password';
if ($username == 'John' && $password == 'password') {
//display text file
}
else {
echo 'You must login to view logfile.txt';
}Code: Select all
<html>
<form action="loginhandler.php" method="get">
<input type="text" name="username" size="24">
<p><input type="password" name="password" size="24"></p>
<p><input type="submit"></p>
</form>
</html>Code: Select all
<?php
if ($username == 'John' && $password == 'password') {
//display text file
}
else {
echo 'You must login to view logfile.txt';
}
?>Code: Select all
<html>
<span style="color:red"><?php echo $errmsg; ?></span>
<form action="loginhandler.php" method="post">
<input type="hidden" name="submitted" value="yes">
<p><input type="text" name="username" size="24"></p>
<p><input type="password" name="password" size="24"></p>
<p><input type="submit"></p>
</form>
</html>Code: Select all
<?php
$submitted = preg_replace('/[^a-zA-Z]/', '', $_POST['submitted']);
$errmsg = '';
$valid = false;
if ($submitted == 'yes') {
$username = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['username']);
$password = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['password']);
if ($username == 'John' && $password == 'password') {
$valid = true;
} else {
$errmsg = 'You must login to view logfile.txt';
}
}
if ($valid) {
//display text file
} else {
//display sign-in form with $errmsg
}
?>Code: Select all
<?php
$submitted = preg_replace('/[^a-zA-Z]/', '', $_POST('submitted')
$errmsg = '';
$valid = false;
if ($submitted == 'yes') {
$username = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['username');
$password = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['password');
if ($username == 'John' && $password == 'password') {
$valid = true;
} else {
$errmsg = 'You must login to view logfile.txt';
}
}
if ($valid) {
//display text file
} else {
//display sign-in form with $errmsg
}
?>Code: Select all
<?php
$submitted = preg_replace('/[^a-zA-Z]/', '', (isset($_POST['submitted']) ? $_POST['submitted'] : null));
$errmsg = '';
$valid = false;
if ($submitted == 'yes') {
$username = preg_replace('/[^a-zA-Z0-9]/', '', (isset($_POST['username']) ? $_POST['username'] : null));
$password = preg_replace('/[^a-zA-Z0-9]/', '', (isset($_POST['password']) ? $_POST['password'] : null));
if ($username == 'John' && $password == 'password') {
$valid = true;
} else {
$errmsg = 'You must login to view logfile.txt';
}
}
if ($valid) {
?>
The text.
<?php
} else {
?>
<html>
<span style="color:red"><?php echo $errmsg; ?></span>
<form action="loginhandler.php" method="post">
<input type="hidden" name="submitted" value="yes">
<p><input type="text" name="username" size="24"></p>
<p><input type="password" name="password" size="24"></p>
<p><input type="submit"></p>
</form>
</html>
<?php
}Code: Select all
<?php
$username = $_GET["username"];
$password = $_GET["password"];
if ($username == 'John' && $password == 'password') {
//display text file
}
else {
echo 'You must login to view logfile.txt';
}
?>Code: Select all
<html>
<form action="loginhandler.php" method="get">
<input type="text" name="username">
<p><input type="password" name="password"></p>
<p><input type="submit"></p>
</form>
</html>Code: Select all
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?google.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?google.com.*$ [NC]
RewriteRule \.(txt)$ - [F]