PHPBuilder - Login script (no database needed)



RSS Twitter
Snippets Http

Login script (no database needed)

by: Niklas Forsberg
|
January 8, 2002

Version: 1.0

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: This little snippet is a login script wich works like the .htaccess file. But you wont need any database setup. Very userfriendly, just cut n paste... =P



2 parts for installing this script:

     1. Save this first information in a file (ex. login.pwd).
     2. Include the include tag to the PHP document you want to secure.



SAVE THIS IN A FILE:

<?php
    if(!isset($PHP_AUTH_USER)) {
        Header("WWW-Authenticate: Basic realm=\"Title of the restricted area?\"");
        Header("HTTP/1.0 401 Unauthorized");
        exit;
    } else {
        if (
	    
	    ($PHP_AUTH_USER == "username01" && $PHP_AUTH_PW == "password01") || 
	    ($PHP_AUTH_USER == "username02" && $PHP_AUTH_PW == "password02") || 
	    ($PHP_AUTH_USER == "username03" && $PHP_AUTH_PW == "password03")

	) {
	
    	} else {
            Header("WWW-Authenticate: Basic realm=\"Try again!\"");
            Header("HTTP/1.0 401 Unauthorized");
	    Print "

PRINT SOME HTML HERE WICH WILL BE SHOWN IF YOU ENTER WRONT USER/PASS 3 TIMES.

";
            exit;
        }
    }
?>




INCLUDE THIS IN THE BEGINNING OF THE PHP DOCUMENT YOU WANT TO SECURE:

<?php
	include("source/to/login.file");
?>



Thats about it =)

Thanks for me...

// Copycat

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Niklas Forsberg

Comment:



Comment:

(Maximum characters: 1200). You have characters left.