WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : Simple Password example
Categories : PHP, Authentication, Security, HTTP Click here to Update Your Picture
tedd sperling
Date : Apr 17th 2006
Grade : 2 of 5 (graded 6 times)
Viewed : 28060
File : 4374.zip
Images : No Images for this code example.
Search : More code by tedd sperling
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

The following is simple password protection scheme.

Create a folder and place the following two files into it, namely "index.php" and "auth.php".

The secret is simply to call the auth.php (require_once) for any document you want to protect in the folder. That way if your script is called, it first loads in the auth.php script and checks the user ID and password. If user ID and password don't match, then the auth script ends prohibiting access to the remaining script. However -- if they do match, then the auth script allows any code thereafter to run. Pretty simple.

So, replace the index.php with whatever you want (keeping the require_once segment) and use the auth.php "as is". Oh, remember to replace the user ID and password to what you want.

To see a working example, please review:

http://www.xn--ovg.com/pw

tedd



index.php
<?php     
require_once ("auth.php");
?>

<!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=ISO-8859-1">
    <title>Password by tedd</title>   

</head>

<body>

    <h1>tedd's password demo</h1>
   
</body>
</html>


auth.php
<?php

    $id
= "test";    // user id
   
$pw = "test";    // password
   
    // Check to see if $PHP_AUTH_USER already contains info

   
if (!isset($_SERVER['PHP_AUTH_USER']))
        {

       
// If empty, send header causing dialog box to appear

       
header('WWW-Authenticate: Basic realm="My Private Stuff"');
       
header('HTTP/1.0 401 Unauthorized');
        exit;
        }
    else if (isset(
$_SERVER['PHP_AUTH_USER']))
        {
        if ((
$_SERVER['PHP_AUTH_USER'] != $id) || ($_SERVER['PHP_AUTH_PW'] != $pw))
            {
           
header('WWW-Authenticate: Basic realm="My Private Stuff"');
           
header('HTTP/1.0 401 Unauthorized');
            exit;
            }
        else
            {
           
// do nothing, everything is OK -- all programs that call this will pass here
           
}
        }
?>



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
Authenticator for Exchange Server LDAP
Categories : PHP, Authentication, LDAP, Security, Sessions
phpSecurePages is a PHP module to secures pages with a loginname and password. It handles multiple user groups (each has own viewing rights), store data in a MySQL database or a configuration file, and can be used to identify Web site viewers.
Categories : PHP, Security, Authentication
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
redirect redirection ip address authentication authenticate addr
Categories : Authentication, HTTP, Network, PHP
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page.
Categories : PHP, Sessions, Security, Authentication
PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character.
Categories : PHP, Algorithms, Security, Authentication, Encryption
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP
IP Blocking
Categories : PHP, Security, HTTP
Authentication HTTP protocol POST
Categories : Authentication, HTTP, PHP
Password using php, Javascript, and html form
Categories : Security, PHP, Authentication, Java Script
Form Security - Match A Value For Success
Categories : PHP, Authentication, HTML and PHP, Sessions, Security
Password protection for Phorum 3.1.x with userlevels and log.
Categories : PHP, MySQL, Authentication, Security
Function to generate readable/remeberable random password
Categories : PHP, Security, Security