少量、頻繁變更、不想建表的配置項 (如站點標題、維護模式開關、API 金鑰)。以 PHP 陣列回傳格式儲存,`include` 即可直接使用,效能極高 (OPcache 直接緩存)。
<?php return [
'site_title' => 'My Awesome Site',
'maintenance' => false,
'api_key' => 'sk_live_xxxxx',
];
<?php
$file = __DIR__ . '/config.php';
$key = $_POST['key'] ?? '';
$val = $_POST['value'] ?? '';
if (!$key) exit('Key required');
// 1. 讀取現有配置 (安全: 只執行 return 陣列)
$config = include $file;
if (!is_array($config)) $config = [];
// 2. 更新值
$config[$key] = $val;
// 3. 產生新檔案內容 (var_export 輸出合法 PHP 代碼)
$content = "
| 序列 | 含義 |
|---|---|
| `\n` | 換行 (LF) |
| `\r` | 回車 (CR) |
| `\t` | Tab |
| `\\` | 反斜線 |
| `\$` | 美元符號 |
| `\"` | 雙引號 |
| `\xHH` | 十六進位字元 |
| `\OOO` | 八進位字元 |