Login on production server doesn't work

眉间皱痕 提交于 2019-12-24 02:23:58

问题


On local server it works, but when I try to login on production server I get this message:

PHP Notice – yii\base\ErrorException
Array to string conversion    

1. in /var/www/html/vendor/yiisoft/yii2/web/User.php at line 240
2. in /var/www/html/vendor/yiisoft/yii2/web/User.php – yii\base\ErrorHandler::handleError(8, 'Array to string conversion', '/var/www/html/vendor/yiisoft/yii...', 240, ...) at line 240
3. in /var/www/html/common/models/LoginForm.php – yii\web\User::login(common\models\User, 2592000) at line 59
4. in /var/www/html/frontend/controllers/SiteController.php – common\models\LoginForm::login() at line 81

Files on local and production servers are the same.


回答1:


Line 240 from yii2/web/User.php is

$log = "User '$id' logged in from $ip with duration $duration.";

So see if $id or $ip or $duration is an array. You are doing something wrong someplace.

Can you post what $_SERVER['REMOTE_ADDR'] is?




回答2:


It is happening due to the id field in the user database model is not a primary key. Simply add the PK constraint to user->id filed from the database.

From DB console:

ALTER TABLE `user` ADD PRIMARY KEY(`id`);

Or any visual tools like phpMyAdmin there is a primary key add functionality from the "Structure" tab.



来源:https://stackoverflow.com/questions/27681505/login-on-production-server-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!