在 config.inc.php 中設定 $cfg['Servers'][$i]['auth_type']:
| 模式 | 值 | 機制 | 適用場景 | 安全性 |
|---|---|---|---|---|
| Config | 'config' | 直接讀取設定檔帳密,無登入畫面 | 本機開發、受信任內網 | ⭐ 低(帳密寫在檔案) |
| HTTP | 'http' | 瀏覽器原生 Basic Auth 對話框 | Apache + mod_php | ⭐⭐ 中 |
| Cookie | 'cookie' | PHP Session + Cookie 表單登入 | 所有環境(含 IIS、Nginx) | ⭐⭐⭐ 高(推薦) |
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root'; // 預設用戶(可留空)
$cfg['Servers'][$i]['password'] = ''; // 預設密碼(可留空)
$cfg['Servers'][$i]['AllowNoPassword'] = false; // 禁止空密碼登入
$cfg['Servers'][$i]['LoginCookieValidity'] = 1440; // 登入有效期(秒),預設 1440=24hr
$cfg['Servers'][$i]['LoginCookieStore'] = 0; // 0=瀏覽器關閉失效,1=永久記住
$cfg['Servers'][$i]['AllowThirdPartyFraming'] = false; // 防止被 iframe 嵌入
⚠️ HTTP 認證僅在 Apache + mod_php (DSO) 模式下運作。
若使用 IIS + PHP (CGI/FastCGI)、Nginx + PHP-FPM,HTTP 認證無法運作,必須改用 Cookie 模式。
pma_7x9k2/)session.save_path 目錄權限、session.gc_maxlifetime 設定config.inc.php 中 $cfg['Servers'][$i]['host']、port、socket 正確