自动登录phpMyAdmin

自动登录phpMyAdmin,php,mysql,cookies,login,phpmyadmin,Php,Mysql,Cookies,Login,Phpmyadmin,我们想在phpMyAdmin中自动登录用户。现在我们有了一个用PHP编写的web界面。用户可以登录。登录后,他们可以单击打开phpMyAdmin的菜单中的SQL链接。有没有办法让他们自动登录?是否可以为phpMyAdmin或其他东西设置cookie以允许他们使用它? 我们不想关闭phpMyAdmin的登录;每个用户都有自己的MySQL用户/密码组合。因此,我们需要将用户名/密码设置传递给phpMyAdmin。您只需在名为pma\u username的字段中发布用户名,并在pma\u passwo

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

您只需在名为
pma\u username
的字段中发布用户名,并在
pma\u password
中发布密码即可。或者,如果您使用http身份验证模式,您可以创建一个带有用户名和密码的链接,如
http://user:pass@www.host.com/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

/* 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';
}
查找blow代码

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

$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'your_password';
如果您的密码为null或“”,请取消对吹扫线的注释

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


那就好了

有时,在本地环境中工作时,每次登录都会让人烦恼。 要避免这种情况,您可以执行以下操作:

在文件底部添加以下行:

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';
}
然后关闭数据库服务器并重新启动。 现在检查&您将看到您将在不输入用户名和密码的情况下登录。

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';
}

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

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

许多web托管提供商都会这样做,但我认为他们会构建自定义身份验证来检查后端登录。我不确定是否有任何现成的东西(尽管可能),我想,由于PHPMyAdmin是开源的,这些网站只是在更改代码以接受来自自己网站的帖子。但这是一个猜测。请参见同一问题:)由于phpMyAdmin中存在一个配置,因此您不应该求助于
hacky
解决方案。下面的答案给出了一个更好的解决方案。在这方面,它是
用户
而不是
用户名
。裁判:糟糕!糟透了!成功的理由!将“cookie”更改为“config”的第一行是使PMA记住密码的原因。否则,您每次都必须输入PW!请不要编辑此帖子。这个定义很好用。谢谢