52

We want to auto login users in phpMyAdmin. Now we have a web-interface, written in PHP. Users can login. After logging in, they can click on the SQL link in the menu that opens phpMyAdmin. Is there a way to log them in automatically? Is it possible to set cookies for phpMyAdmin or something to let them use it? We don't want to turn off phpMyAdmin's login; each user has his own MySQL user/pass combination. So we need to pass the username/password settings to phpMyAdmin.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
www.data-blogger.com
  • 4,076
  • 7
  • 43
  • 65
  • Many web hosting providers do this, but I think they build custom authentication to check against their back-end login. Not sure whether anything exists out of the box for this (it might, though) – Pekka Apr 16 '11 at 16:42
  • I imagine that since PHPMyAdmin is open source, these sites are simply changing the code to accept a POST from their own site. But that's a guess. – Mikecito Apr 16 '11 at 16:47

6 Answers6

88

Add code in config.inc.php below of /* Authentication type */. It exists in the root folder

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; 
Arun Kushwaha
  • 1,136
  • 1
  • 8
  • 8
  • 2
    the first line where you change 'cookie' to 'config' is what causes PMA to remember the password. Otherwise, you will have to enter the PW each time! – Noam B. Nov 18 '19 at 16:57
39

Edit config.inc.php

Location : /etc/phpmyadmin/config.inc.php

Find for the blow code

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

And replace the line of code by blow code

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

If your password null or '' the uncomment the blow line

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

to

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

then it will work fine !

abSiddique
  • 11,647
  • 3
  • 23
  • 30
25

You can simply post the username in a field named pma_username and the password in pma_password. Or, if you're using http auth mode you can create a link with username and password like http://user:pass@www.host.com/phpmyadmin/...

saladi
  • 3,103
  • 6
  • 36
  • 61
markus
  • 40,136
  • 23
  • 97
  • 142
  • See [this discussion](http://stackoverflow.com/questions/4174317/what-is-crossdomain-xml-file/4174355?noredirect=1#comment16322199_4174355) on the same matter :) – JNF Jan 21 '15 at 21:17
  • Since there is a configuration that exists in phpMyAdmin, you should not resort to a `hacky` solution. The answers following this answer give a much better solution. Regards, – Junaid Qadir Shekhanzai Dec 22 '19 at 09:15
12

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';
}
gjerich
  • 369
  • 3
  • 6
4

Sometimes when working at your local environment it annoys to login each time. To avoid it you can do the following:

Add following lines at bottom of file:

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

After that shutdown your db server & restart again. Now check & you will see that you will login without entering user name & password.

MyO
  • 413
  • 1
  • 8
  • 19
2

Things are much easier in 2020 if you need this for development. Just set environment variables:

PMA_USER: "the-root"
PMA_PASSWORD: "the-password"
rubenhak
  • 830
  • 2
  • 10
  • 28