自动登录phpMyAdmin


Auto-login phpMyAdmin

我们想在phpMyAdmin中自动登录用户。现在我们有了一个用PHP编写的web界面。用户可以登录。登录后,他们可以点击菜单中打开phpMyAdmin的SQL链接。有办法让他们自动登录吗?是否有可能为phpMyAdmin或其他东西设置cookie,让他们使用它?我们不想关闭phpMyAdmin的login;每个用户都有自己的MySQL用户/通行证组合。因此,我们需要将用户名/密码设置传递给phpMyAdmin.

在config.inc.php中添加/*认证类型*/下面的代码。它存在于根目录

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; 

编辑config.inc.php

路径:/etc/phpmyadmin/config.inc.php

查找吹码

$cfg['Servers'][$i]['auth_type'] = 'cookie';

用blow代码

替换该行代码
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'your_password';

如果您的密码为空或"取消注释的吹行

//$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

您可以简单地在名为pma_username的字段中发布用户名,在pma_password中发布密码。或者,如果您使用http认证模式,您可以创建一个用户名和密码链接,如http://user:pass@www.host.com/phpmyadmin/...

config.inc.php

/* Authentication type */
//$_SERVER["REMOTE_ADDR"] == '::1' (**ipv6**)
//$_SERVER["REMOTE_ADDR"] == '127.0.0.1' (**ipv4**)
if ($_SERVER["REMOTE_ADDR"] == '::1') {
    $cfg['Servers'][$i]['auth_type'] = 'config';
    $cfg['Servers'][$i]['user'] = 'user';
    $cfg['Servers'][$i]['password'] = 'password';
} else {
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
}

有时在本地环境下工作时,每次登录都很烦人。为了避免它,你可以这样做:

在文件底部添加以下行:

phpmyadmin ' config.inc.php

$cfg['LoginCookieValidity'] = 10000; // Keep long validity :)-
$cfg['Servers'][$i]['user']          = 'root'; // Your user name
$cfg['Servers'][$i]['password']      = 'root'; // Your password
$cfg['Servers'][$i]['auth_type']     = 'config';

之后关闭你的数据库服务器&再次重启。现在检查&您将看到登录时不需要输入用户名&密码。

如果你需要这个来开发,那么在2020年事情会容易得多。只需设置环境变量:

PMA_USER: "the-root"
PMA_PASSWORD: "the-password"