$this->Auth->login() 创建返回 1 行的正确查询,但 IF 检查失败(服务器特定问题) [英] $this->Auth->login() creates correct query that returns 1 row, but fails IF check (server specific issue)

查看:12
本文介绍了$this->Auth->login() 创建返回 1 行的正确查询,但 IF 检查失败(服务器特定问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个网站,我们要迁移到新服务器.在旧服务器上一切正常.这只是一个网站的开始,所以它非常简单.

We have a site that we're moving to a new server. Everything worked fine on the old server. It's just the start of a site, so it's pretty bare-bones.

当移动到我们的新服务器时,尝试登录不再有效.但是 - 根据 debugKit,由 $this->Auth->login() 生成的查询:

When moving to our new server, trying to log-in no longer works. BUT - according to debugKit, the query generated by $this->Auth->login():

SELECT `User`.`id`, `User`.`name`, `User`.`email`, `User`.`username`, `User`.`password`, `User`.`role`, `User`.`created`, `User`.`modified` 
FROM `shopping_main`.`users` AS `User` 
WHERE `User`.`username` = 'another' 
AND `User`.`password` = '3813dd3a5eeb39c857d56f9ae58ec7f8237e5eb3' 
LIMIT 1

IS 返回 1 行 - 但如果块失败:

IS returning 1 row - yet this if block fails:

if ($this->Auth->login()) {
    $this->Session->setFlash(__('You are now logged in.'));
} else {
    $this->Session->setFlash(__('Invalid username or password, try again'));
}

两个(相同版本)都安装了 PDO - 不确定这是否重要,但我们之前遇到过奇怪的问题.

PDO is installed on both (same version) - not sure if that matters, but we've had weird issues before w/ that.

在全新安装 CakePHP 2.2 stable 时,一切都亮起绿色(数据库连接、modrewrite...等)

When doing a fresh install of CakePHP 2.2 stable, everything lights up green (database connection, modrewrite...etc etc.)

我本以为我们的数据或代码...等有问题,但是 - 这是相同的数据,相同的代码,并且通过它确实返回 1 行这一事实得到了验证.

I would have thought there was something wrong with our data, or code...etc, but - it's the same data, the same code, and that's verified by the fact that it DOES return 1 row.

下面是我最近在 AppController 中的 $components 数组:

Below is my most recent $components array in the AppController:

public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Cookie',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'dashboard', 'action' => 'index', 'admin'=>true),
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'admin'=>true)
    )
);

<小时>

更新:

根据我们的服务器人员的说法,我们遇到问题的服务器是唯一一个安装了 PECL 的服务器 - 当他删除它时,登录成功了.(我们在服务器上需要它做其他事情 - 为什么/什么会导致我们的登录无法正常工作?)

According to our server guy, the server we're having the issue on is the only one with PECL intalled - when he removed it, the login worked. (We need it on the server for other things - why/what would cause that to keep our login from working?)

推荐答案

原海报回答(我):

据我们的服务器人说,加载PDO有两种方法.第一种是使用easyapache安装PDO php扩展.第二种是通过PECL安装PDO.看起来有问题的模块不同."

According to our server guy, "There are two ways to load PDO. The first is by using easyapache to install the PDO php extension. The second is by installing the PDO via PECL. It appears that the modules in question are different."

显然,这个服务器上有 PECL 而不是普通的 easyapache PDO.当他删除它,并使用 easyapache PDO 重新启动/重置它时,一切都很好.

Apparently, this server had PECL on it instead of the normal easyapache PDO. When he removed that, and restarted/reset it with the easyapache PDO, everything worked great.

所以 - 听起来像 CakePHP 需要正常"的 PDO.

So - sounds like CakePHP requires the "normal" PDO.

谜团解开.

如果您有 PECL,则可以使用以下解决方法:

If you have PECL instead, you can use this workaround:

  1. 在您的数据源文件夹中创建一个文件HpMysql.php"并添加以下代码/类:https://github.com/lorenzo/HipHop/blob/master/Model/Datasource/Database/HpMysql.php

将您的 database.php 'datasource' 更改为 'HpMysql'

Change your database.php 'datasource' to 'HpMysql'

这篇关于$this->Auth->login() 创建返回 1 行的正确查询,但 IF 检查失败(服务器特定问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆