Re: Pear Auth Class (Newbie)

From: Date: Thu, 06 Dec 2001 20:40:41 +0000
Subject: Re: Pear Auth Class (Newbie)
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-575@lists.php.net to get a copy of this message
On Thu, 6 Dec 2001 18:54:00 -0000, Simon Hamilton wrote: >Does anyone have any working examples of the Pear Auth Class. I'm a bit of >a beginner with PHP, especially Classes. <?php require_once "Auth/Auth.php"; // We use a MySQL as storage container in this example $a = new Auth("DB","mysql://martin:test@localhost/test"); // Detect, if the user is already logged in. If not, draw the // login form. $a->start(); if ($a->getAuth()) { echo "Welcome user ".$a->getUsername()."!<br />\n"; // output the content of your site, that is only visible // for users which have been authenticated successfully. } ?> More examples for using PEAR::Auth can be found in the API documentation of Auth.php. >I have a permissions >table with a column for each page of my site. Then I have one row for each >group, and a "yes" or "no" in each field under the appropriate column to say >whether they have permission to that page or not. > >I also use a separate table called TBLAuth where I keep username, password, >group (for the permissions table), etc. > >So when a user logs onto my site, the auth system will check their >permissions and direct them to the appropriate home page. This cannot be done with the default settings of PEAR::Auth. The only way to do this is to create a customized storage container that queries the table that contains username/password and that queries the table that contains the permissions. >And as they >browse through the site, each page will check that they have the right user >level (group) permission to proceed, or "ACCESS DENIED" type of thing. Please have a look at the attached file. This is a quick hack (untested), that implements something like permission handling in a customized storage container. As I said, it is a quick hack (< 2 min of work) and may not work at all, but perhaps it's a start for you. If you have more questions, don't hesitate to ask. - Martin -- Martin Jansen, <mail@martin-jansen.de> http://www.martin-jansen.de/

« previous php.pear.general (#575) next »