Integrating CakePHP with PEAR:Auth
Monday, 4 September 2006
If you have a web-site which uses PEAR::Auth, and another section of your site using CakePHP, you’d probably find it baffling that your CakePHP doesn’t remember your authentication cookie. In addition, CakePHP wouldn’t redirect properly after logging in.
The main reason is CakePHP overrides the standard PHP session environment, see cake/lib/session.php
ini_set('session.use_trans_sid', 0);
ini_set('session.name', CAKE_SESSION_COOKIE);
ini_set('session.cookie_lifetime', $this->cookieLifeTime
ini_set('session.cookie_path', $this->path);
ini_set('session.gc_probability', 1);
The solution is to change admin/config/core.php
define('CAKE_SESSION_SAVE', null);
The other problem you’d encounter is because the REQUEST_URI points to the base controller PHP file, and not your current URL. In your controller file, say, app/controller/blogs_controller.php
function beforeFilter()
{
this->checkSession();
}
function checkSession()
{
require_once("MDB2.php");
require_once("Auth.php");
require_once("../../../config.php");
$auth = new Auth("DB", $dsn, "", false);
$auth->start();
if (!$auth->checkAuth())
{
$returnURL = $_SERVER['REDIRECT_URL'];
header("Location: /login.php?return=" . $returnURL);
exit;
}
}
No. 1 — July 25th, 2007 at 7:56 pm
[...] http://www.redmountainsw.com/wordpress/archives/integrating-cakephp-with-pearauth にあった方法で解決したのでメモ。 [...]