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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: