Error: Could not fetch http://thedevnet.com/wp-content/plugins/gd-star-rating/css/gdsr.css.php?t=0&s=a10i10m20k20c05r05%23121620243046%23121620243240%23s1pchristmas%23s1pcrystal%23s1pdarkness%23s1poxygen%23s1goxygen_gif%23s1pplain%23s1ppumpkin%23s1psoft%23s1pstarrating%23s1pstarscape%23t1pclassical%23t1pstarrating%23t1gstarrating_gif&ver=1.7.2 for caching. You might need to exclude this file in WP Minify options. The Developer Network – PHP User Management Script Using htaccess

PHP User Management Script Using htaccess

In PHP, adding, setting up, or managing user management can be quite tedious and can quickly overwhelm a webmaster. Having a nice class that can manage your authentication, user setup, and permissions will really speed up the process. This is not easy, but this class will take a lot of the workload out it for you.
This class utilizes Apache .htaccess and .htgroup files to define users, groups and passwords. Additionally, you can use the class to manage extra information for users, stored in a third file.

Test (this will ensure the user management class is working properly:

  1. <?php
  2. /*****************************************************************************
  3.   | @script_type –  PHP Example-Script
  4.   | ————————————————————————-
  5.   | http://thedevnet.com/php/classes/php-user-management-script-using-htaccess/
  6.   | $Id: setup_test.php,v 1.1 2009/10/18 19:58:58 horst Exp $
  7.  ****************************************************************************/
  8.  
  9. error_reporting(E_ALL ^E_NOTICE);
  10.  
  11. # embedd classfile
  12.  
  13.     require_once(dirname(__FILE__).'/../_libs/example_class.inc.php');
  14.  
  15.  
  16. # to define HTPASSWDPATH and HTUSERFILE is mandatory,
  17. # to define (and use) HTGROUPFILE or HTINFOFILE both is optional
  18.  
  19.     define('HTPASSWDPATH', dirname(__FILE__).'/../_htfiles/');
  20.     define('HTUSERFILE',   '.htuser');
  21.     define('HTINFOFILE',   '.htinfo');    // if you use infos and also want the user let it edit too, enabled it, otherwise it should be disabled
  22.     define('HTGROUPFILE',  '.htgroup');   // isn't needed for the ChangePassword-Form, and can be disabled for performance reason (reading and parsing one file more or less, _every_time_!)
  23.  
  24.  
  25. # initialize the class
  26.     # param 1: URL of this script, needed for Redirections and Formactions
  27.     # param 2: (optional) array with admin-userid/s
  28.     # param 3: (optional) name of the admin group
  29.  
  30.     $ht = new hn_htusers($_SERVER['PHP_SELF'], array('XyZ'), 'admins');
  31.     $ht->setup_test();
  32.  
  33. ?>

Example PHP HTTP Authentication:

  1. <?php
  2. if(!isset($_SERVER['PHP_AUTH_USER']))
  3. {
  4.     header('WWW-Authenticate: Basic realm="hn_htusers"');
  5.     header('HTTP/1.0 401 Unauthorized');
  6.     echo '401 Unauthorized! Accessing this page needs a valid useraccount, sorry!';
  7.     exit();
  8. }
  9. ?>

An example form for Administrators:

  1. <?php
  2. /*******************************************************************************\
  3.   * @script_type –  PHP-Script
  4.   * —————————————————————————
  5.   * $Source: http://thedevnet.com/php/classes/php-user-management-script-using-htaccess/
  6.   * $Id: example.woh4.php,v 1.1 2009/10/16 17:05:42 horst Exp $
  7. \*******************************************************************************/
  8.  
  9. include('htaccess.inc.php');
  10. $hn_let_only_admins_pass = TRUE;
  11.  
  12. // sets the used htfiles to users, groups and infos
  13. $htfiles = 3;
  14. include('../example_manager.inc.php');
  15.  
  16. ?>
htaccess PHP User Management
hn_htusers-2009-10-28.zip
Version: 1.1

376.1 KiB
60 Downloads
Details…

GD Star Rating
loading...

Originally posted 2009-11-09 21:26:27.

Popularity: 40%

Posted by natster   @   12 February 2010

Related Posts

Like this post? Share it!

RSS Digg Twitter StumbleUpon Delicious Technorati Facebook

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

You must be logged in to post a comment.

Previous Post
« 2D Plotter
Next Post
PHP Generate RSS Feeds »
Powered by Wordpress   |   Lunated designed by ZenVerse