我在 wp-config.php 中使用以下代码并为我工作。
将会话存储在数据库中的 Codeigniter 中。
Codeigniter 版本 3.xx
define('BASEPATH', 2021);
require_once(__DIR__.DIRECTORY_SEPARATOR.'panel'.DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR."database.php");
$cisess_cookie = $_COOKIE['ci_session'];
$cisess_connect = mysqli_connect($db[$active_group]['hostname'], $db[$active_group]['username'], $db[$active_group]['password']);
if (!$cisess_connect) {
die("<div class='error'>" . mysqli_error($cisess_connect) . "</div>");
}
$cisess_query = "SELECT data FROM sessions WHERE id = '$cisess_cookie' LIMIT 1";
mysqli_select_db($cisess_connect,$db[$active_group]['database']);
$cisess_result = mysqli_query($cisess_connect,$cisess_query);
if (!$cisess_result) {
die("<div class='error'>" . mysqli_error($cisess_connect) . "</div>");
}
$cisess_row = mysqli_fetch_assoc($cisess_result);
$session_data = $cisess_row['data'];
$return_data = array();
$offset = 0;
while ($offset < strlen($session_data)) {
if (!strstr(substr($session_data, $offset), "|")) {
throw new Exception("invalid data, remaining: " . substr($session_data, $offset));
}
$pos = strpos($session_data, "|", $offset);
$num = $pos - $offset;
$varname = substr($session_data, $offset, $num);
$offset += $num + 1;
$data = unserialize(substr($session_data, $offset));
$return_data[$varname] = $data;
$offset += strlen(serialize($data));
}
print_r($return_data);
exit;