1
나는 zend에 익숙하고 나는 그것이 mvc와 어떻게 작동하는지 거의 이해한다. 그러나 나는 비 mvc 프로젝트에서만 zend_auth를 사용하려고 노력하고있다. 로그인 (인증) 부분은 작동합니다 (최선의 방법인지 확실하지 않더라도). 그러나 사용자가 로그인 할 때 저장되는 데이터를 다른 곳에서 가져 오는 방법을 알아낼 수 없습니다. 페이지. 여기 내 login.php입니다 :mvc없이 Zend_auth. 어떻게 사용자 데이터를 얻는가
<?php
ini_set('display_errors', 1);
// define an absolute path to library directory
// you don't have to set a constant but it is just good practice
// you can also use a variable or add the path directly below
define('APPLICATION_LIBRARY','c:/xampp/htdocs/website/');
// Note again: the path is the parent of your Zend folder, not the Zend folder itself.
// now set the include path
set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_LIBRARY, get_include_path(),
)));
include("config.php");
// i'm testing with a username and password that i know is inside database in the actual code is: $username= $_POST['username'] and the same for password.
$username ='userx';
$password = 'passx';
$auth = Zend_Auth::getInstance();
$adapter = new Zend_Auth_Adapter_DbTable($db);
$adapter ->setTableName('profiles')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setIdentity($username)
->setCredential($password);
$result = $auth->authenticate($adapter);
switch($result->getCode()) {
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
$errorMessage = "Error: Name not correct.";
// i'm sending username and password to another login that is exactly like this one, but searches in another table
header("Location: login2.php?pass=".$password."&user=".$username);
break;
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
$errorMessage = "Error: pass and user are not valid";
echo $errorMessage;
header("Location: login2.php?pass=".$password."&user=".$username);
break;
case Zend_Auth_Result::SUCCESS:
$adapter->getResultRowObject();
$authStorage = $auth->getStorage(); // set storage. Session default
$authStorage->write($result); // save user data
if(isset($_POST['remember'])) {
Zend_Session::rememberMe(60*60*24*7*4);
$remember=$_POST['remember'];
}
// send user to page they originally request, with username and pass because i don't know how to get them there from what i've stored before...i know it's not good.
header("Location: profile_page.php?pass=".$password."&user=".$username."&remember=".$remember);
break;
default:
$errorMessage = "Error.";
break;
}
?>
이 내 config.php 파일입니다 :
<?php
error_reporting(E_ALL);
require_once('Zend/Session/Namespace.php');
require_once('Zend/Session.php');
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');
require_once('Zend/Auth/Exception.php');
require_once('Zend/Controller/Action.php');
$params = array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'dbname' => 'website',
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $params);
$db->getConnection();
} catch(Zend_Db_Adapter_Exception $e) {
die("<pre>There was an error connecting to the server</pre>"); //Probably bad login or mysql daemon is not running.
} catch(Zend_Exception $e) {
die("<pre>Something failed to load</pre>"); //factory() probably failed to load the adapter class
}
$users = new Zend_Session_Namespace('Zend_Auth');
?>
나는 사용자가 자신의 프로필 페이지에서 인증 할 때 저장되어있는 데이터를 얻을 싶어요.) ($ 정식 = Zend_Auth ::의 getInstance;
을 저장소에 잘못된 일을 wrting된다 $ username = $ auth-> getIdentity() -> 사용자 이름; –
와우 !! 그것은 작동합니다! 아주, 아주, 아주, 아주 고마워요 !!! –