Home arrow PHP arrow Page 6 - User Authentication with patUser (part 1)

A Different Realm - PHP

Need to add authentication to your PHP-based Web application? Getit done in a jiffy with patUser, a PHP class which makes it possible torapidly add powerful user management capabilities to your Web application.

TABLE OF CONTENTS:
  1. User Authentication with patUser (part 1)
  2. Power User
  3. Dump Truck
  4. Zone Six
  5. Breaking It Down
  6. A Different Realm
  7. Icing On The Cake
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 15
April 23, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
If you'd prefer not to futz around with templates, patUser also supports plain-vanilla HTTP authentication. In this case, the browser takes care of displaying a login box; patUser merely verifies the credentials entered by the user into that box.

In order to enable this type of authentication, all you need to do is forget to connect patUser to a patTemplate object. Since patUser will not have a template to use for the login box, it will automatically fall back to using HTTP authentication. Consider the following script, which illustrates:


<?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db111", "us111", "secret"); // initialize patUser $u = new patUser(true); // connect patUser to database $u->setAuthDbc($db); // set realm for display $u->setRealm("Highly Secure Zone"); // check credentials before displaying page $uid = $u->requireAuthentication("displayLogin"); // restricted page goes here ?> <html> <head> <basefont face="Arial"> </head> <body> <center> <h2>Welcome to Zone 6!</h2> <u>This is a restricted zone. Trespassers will be vaporized.</u> </center> <p align="right"> Your user ID is <?=$uid?> <br> <a href="logout.php">Log out</a> </body> </html>
Here's what the result might look like:



Note my introduction of a new method in the script above, the setRealm() method. This method is used to set the name of the realm for HTTP authentication, and appears in the login box displayed by the browser.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: