We can use the Zend Login for our existing website without using whole Zend Library. Zend Auth module provides the more secure login.
First we need to download the following folders and files from Zend Library
1. Zend/Db/
2. Zend/Auth/
3. Zend/Session/
4. Zend/Db.php
5. Zend/Auth.php
6. Zend/Session.php
7. Zend/Exception.php
Then you can use the below code in your login.
require_once('Zend/Db/Table/Abstract.php');
require_once('Zend/Auth/Adapter/DbTable.php');
require_once('Zend/Auth.php');
require_once('Zend/Db/Expr.php');
$params = array(
'host' => 'localhost',
'username' => 'support',
'password' => 'vanilla',
'dbname' => 'Training',
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $params);
$db->getConnection();
} catch(Zend_Db_Adapter_Exception $e) {
die("
} catch(Zend_Exception $e) {
die("
}
$uname = 'admin';
$paswd = md5($uname);
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('pwd');
// Set the input credential values
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($uname));
// Perform the authentication query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid()){
print_r($result);
print_r($_SESSION);
echo "Success";
}else{
echo "Failure";
}
First we need to download the following folders and files from Zend Library
1. Zend/Db/
2. Zend/Auth/
3. Zend/Session/
4. Zend/Db.php
5. Zend/Auth.php
6. Zend/Session.php
7. Zend/Exception.php
Then you can use the below code in your login.
require_once('Zend/Db/Table/Abstract.php');
require_once('Zend/Auth/Adapter/DbTable.php');
require_once('Zend/Auth.php');
require_once('Zend/Db/Expr.php');
$params = array(
'host' => 'localhost',
'username' => 'support',
'password' => 'vanilla',
'dbname' => 'Training',
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $params);
$db->getConnection();
} catch(Zend_Db_Adapter_Exception $e) {
die("
There was an error connecting to the server"); //Probably bad login or mysql daemon is not running.
} catch(Zend_Exception $e) {
die("
Something failed to load"); //factory() probably failed to load the adapter class
}
$uname = 'admin';
$paswd = md5($uname);
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('pwd');
// Set the input credential values
$authAdapter->setIdentity($uname);
$authAdapter->setCredential(md5($uname));
// Perform the authentication query, saving the result
$result = $auth->authenticate($authAdapter);
if($result->isValid()){
print_r($result);
print_r($_SESSION);
echo "Success";
}else{
echo "Failure";
}