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

The History Channel - 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
patUser allows you to track user movement through your application with a set of history functions, which maintain a buffer of all the URLs visited and provide you with hooks to return to any of them. As you might imagine, this comes in handy if you need to provide users with controls to go back to the previous page, or to show them their browsing history.

The primary method to accomplish this is the keepHistory() method, a call to which should be included on every page of your application. The function accepts two parameters, the size of the history buffer and the title of the current page, and stores the current URL and supplied title in the session for easy retrieval.

Here's a sample of what that history buffer might look like:


Array ( [0] => Array ( [url] => /add_user.php? [title] => Add User ) [1] => Array ( [url] => /patuser/modify_user.php? [title] => Modify User ) [2] => Array ( [url] => /scripts/review.php? [title] => Verify User ) )
Once the history buffer has been created, data from it may be retrieved via the getHistory() method, which returns an array holding a list of all the URLs and pages visited by the user in the current session. The following example illustrates, using the sample data above as reference.

<?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 history $history = $u->getHistory(); // iterate over array // display history with clickable URLs echo "<h2>Your history:</h2>"; echo "<ol>"; foreach ($history as $h) { echo "<li><a href=" . $h['url'] . ">" . $h['title'] . "</a>"; } echo "</ol>"; ?>
An additional goHistory() method makes it possible to send the browser back to a specific page in the buffer via HTTP redirection. Consider the following script, which accepts a number and redirects the browser back that many pages (note that the goHistory() method must be provided with negative values as input):

<?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"); // go back i pages $u->goHistory($_GET['i'] * -1); ?>


 
 
>>> 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: