WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides Click here to Update Your Picture
Christian Haensel
Date : Jun 14th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 4533
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Christian Haensel
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

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");
    }
   
}
?>



Store, retrieve and delete cookies using JavaScript.
Categories : Java Script, Cookies, Beginner Guides, Cookies
Secure Login
Categories : PHP, MySQL, Cookies, Security
session out Timer
Categories : PHP, Sessions, Security, Beginner Guides
Human readable PHP password generator
Categories : PHP, Security, Beginner Guides, Arrays
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
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
Find the day of the week for any given year/month/day.
Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
Function that does language negotiation based on the Accept-Language header, a cookie or host name
Categories : HTTP, PHP, Cookies
Cross Browser Session Starter
Categories : PHP, Sessions, Cookies
PHP and javascript mouseover, mouseout, and mousedown events
Categories : PHP, Java Script, Form Processing, Beginner Guides
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
send_mail function to defeat Header Injection Hacking/Spamming
Categories : PHP, Email, Form Processing, Security
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security