Learning PHP and MySQL

Example 16-4 The login script, called login.php

<?php
//  Example  of  Auth_HTTP  the  also  returns  additional  information  about  the  user
require_once('config.php');
require_once(
'db_login.php');
require_once(
"Auth/HTTP.php");
//  We  use  the  same  connection  string  as  the  pear  DB  functions
$AuthOptions  =  array(
'dsn'=>"mysql://$db_username:$db_password@$db_host/$db_database",
'table'=>"users",  //  your  table  name
'usernamecol'=>"username",  //  the  table  username  column
'passwordcol'=>"password",  //  the  table  password  column
'cryptType'=>"md5",  //  password  encryption  type  in  your  db
'db_fields'=>"*"  //  enabling  fetch  for  other  db  columns
);
$authenticate  =  new  Auth_HTTP("DB",  $AuthOptions);
//  set  the  realm  name
$authenticate->setRealm('Member  Area');
//  authentication  failed  error  message
$authenticate->setCancelText('<h2>Access  Denied</h2>');
//  request  authentication
$authenticate->start();
//  compare  username  and  password  to  stored  values
if  ($authenticate->getAuth())  {
session_start
();
$smarty->assign('blog_title',$blog_title);
$smarty->display('header.tpl');
//setup  session  variable
$SESSION['username']  =  $authenticate->username;
$SESSION['first_name']  =  $authenticate->getAuthData('first_name');
$SESSION['last_name']  =  $authenticate->getAuthData('last_name');
$SESSION['user_id']  =  $authenticate->getAuthData('user_id');
echo  
"Login  successful.  Great  to  see  you  back  ";
echo  
$authenticate->getAuthData('first_name');
echo  
"  ";
echo  
$authenticate->getAuthData('last_name').".<br  />";
$smarty->display('footer.tpl');
}
?>

Posted by on 09/27 at 11:33 AM

Next entry: Example 16-5 SQL to create the posts table

Previous entry: Example 16-3 The footer.tpl file

<< Back to main