| 
<?php
 /* basic realm auth by database */
 
 /**
 * the sql.cls.php found from
 * http://www.phpclasses.org/package/3406-PHP-Execute-common-MySQL-database-SQL-queries.html
 * http://www.phpclasses.org/package/3406/
 */
 include_once 'sql.cls.php';
 class httpBasicAuthThroughDB extends sqlFunctions{
 
 public function isUserAuthorized($p_user, $p_pass){
 $usr=$this->getRowsValX('select * from `users` where `user_id`=\''.self::sqlSafeString($p_user).'\' and `password`=md5(\''.self::sqlSafeString($p_pass).'\') order by `user_id` limit 1');
 return (!is_bool($usr) && is_array($usr));
 }
 
 public function isUserAuthorizedSecure($p_user, $p_pass){
 $usr=$this->getRowsValX('select * from `emp` where `id`=\''.self::sqlSafeString($p_user).'\' and `pass`=\''.self::sqlSafeString($p_pass).'\' order by `id` limit 1');
 return (!is_bool($usr) && is_array($usr));
 }
 
 }
 
 session_start();
 include_once 'http.auth.cls.php';
 $db=new httpBasicAuthThroughDB();
 $db->openMyDatabaseX('localhost', 'root', 'your password', 'your database');
 #$httpauth=new HTTPBasicRealmAuth('authentication by database', $db, 'isUserAuthorized');
 $httpauth=new HTTPBasicRealmAuth('authentication by database', $db, 'isUserAuthorizedSecure', true);
 
 include 'secure.file.eg.php';
 |