Home arrow PHP arrow Page 5 - User Authentication With patUser (part 3)

No Distinguishing Marks - PHP

In this concluding article, find out about how to use patUser toidentify users and groups by different criteria, track a user's clicks, maintain user statistics, and gracefully handle errors.

TABLE OF CONTENTS:
  1. User Authentication With patUser (part 3)
  2. Making Exceptions
  3. The History Channel
  4. Natural Selection
  5. No Distinguishing Marks
  6. Big Brother Is Watching
  7. Endgame
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 6
May 07, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
That isn't all, though - patUser also comes with two other functions, identifyUser() and identifyGroup(), which allow you to identify users and groups by other criteria. Consider the following example, which demonstrates:






<?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db211", "us111", "secret"); // initialize patUser $u = new patUser(true); // connect patUser to database $u->setAuthDbc($db); // set tables $u->setAuthTable("users"); // get UID $uid = $u->identifyUser(array("email" => "tom@some-domain.com")); echo $uid; ?>
This method is essentially a simpler version of the getUsers() method; it checks the user database for matching records and returns the user ID of the found user if available.

You can add as many search criteria as you like, as in the following (equivalent) example:

<?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db211", "us111", "secret"); // initialize patUser $u = new patUser(true); // connect patUser to database $u->setAuthDbc($db); // set tables $u->setAuthTable("users"); // get UID $uid = $u->identifyUser(array("email" => "tom@some-domain.com", "sex" => "M", "age" => 21, "time_online" => 0)); echo $uid; ?>
Similarly, there's also an identifyGroup() method, which can be used to quickly look up a group ID, given the group name (or any other group attribute). Take a look:

<?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db211", "us111", "secret"); // initialize patUser $u = new patUser(true); // connect patUser to database $u->setAuthDbc($db); // set tables $u->setGroupTable("groups"); // get GID $gid = $u->identifyGroup(array("name" => "Operations")); echo $gid; ?>
If no user or group can be found matching the specified criteria, both functions will return false.

 
 
>>> 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 6 - Follow our Sitemap

Dev Shed Tutorial Topics: