|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
This script will provide a very simple cookie-based single-password login without usernames.
The password is defined in this file, so you need to make sure that nobody will see the source.
Edit the variables to suite your needs. This is a very simple solution and should only be used for
private websites and such. Do NOT use this if you need to store sensitive data, as this is really,
really (!) not a secure way to do it !!! This login will only keep regular visitors from the stuff
you don't want them to see.
Cheerio!
Chris
|
<?php
/*
To make this script work, just ad this code to the very top of your page (before any output starts).
Programmed by Christian Haensel, christian@chftp.com, LINK1http://www.chftp.comLINK1
Exclusively published on weberdev.com. If you like my scripts, please let me know or
link to me.
You may copy, redistirubte, change and alter my scripts as long as this information remains
intact.
*/
// Setting the variables
$thepass = "mypassword";
$notlogged = "You need to be logged in to access this page"; // The "Need to be logged in" message
$errormsg = "The password provided did not work out for you"; // The error message
$loc_action = "test.php"; // The action document for the form
$loc_succ = "test.php"; // Location to go to after successful login
$loc_error = $PHP_SELF; // The doc to go to on bad login. You can leave $PHP_SELF in most cases
$but_log = "Login"; // Text on the submit button
$pass = $_POST['pass'];
$logged = $_COOKIE['logged'];
$mod = $_POST['mod'];
// If there is no cookie and the user is not logging in, output the login form
if($logged != "1"&& $mod != "login") {
echo '
<b>'.$notlogged.'</b><p>
<form name="login" action="'.$loc_action.'" method="POST">
<input type="password" name="pass">
<input type="hidden" name="mod" value="login">
<input type="submit" value="'.$but_log.'">
</form>';
// If there is a bad login, the error message will be displayed
if($_GET['msg'] == "err") {
echo '<p><font color="red">'.$errormsg.'</font>';
}
die;
}
// if the user is logging in
elseif($logged != "1"&& $mod == "login") {
// check the password
if($pass == $thepass) {
// if the pass is correct, set the cookie and go to the success page
setcookie("logged", "1");
header("Location: ".$loc_succ);
} else {
// On bad login, go back to where you came from and try it again
header("Location:".$loc_err."?msg=err");
}
}
?> | | |
|
| Secure Login Categories : PHP, MySQL, Cookies, Security | | | Simple Cookie example Categories : PHP, Beginner Guides, Cookies | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP, PHP Classes, Security, GD image library, Security | | | PHP Cookies - Simple cookie write/read methods that allow basic encryption Categories : PHP, Cookies, Security, Encryption | | | Store, retrieve and delete cookies using JavaScript. Categories : Java Script, Cookies, Beginner Guides, Cookies | | | session out Timer Categories : PHP, Sessions, Security, Beginner Guides | | | Simple PHP cookie counter Categories : PHP, Cookies, Beginner Guides | | | Human readable PHP password generator Categories : PHP, Security, Beginner Guides, Arrays | | | Using PHP im HTML image tags Categories : PHP, HTML and PHP, Graphics, Beginner Guides | | | Password protection for Phorum 3.1.x with userlevels and log. Categories : PHP, MySQL, Authentication, Security | | | Newbie Notes #7 - Ridiculous regex Categories : PHP, Beginner Guides, Regexps | | | Generate image with random number (CAPTCHA) Categories : PHP, GD image library, Graphics, Security | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | |
|
|