0
我嘗試在SESSION目錄的文件中存儲多個會話值,但是當我嘗試存儲新值時,它會覆蓋舊值並僅存儲新值。在會話日誌文件中存儲多個用戶會話值
<?php
session_start();
?>
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<?php
$_SESSION['userName'] = 'nancy';
$_SESSION['emailAddress'] = '[email protected]';
$_SESSION['userName'] = 'preeti';
$_SESSION['emailAddress'] = '[email protected]';
$session_data = session_encode(); // Get the session data
// change the name below for the folder you want
$dir = "SESSION";
$file_to_write = 'session_log';
$content_to_write = " $session_data";
if(is_dir($dir) === false)
{
mkdir($dir);
}
$file = fopen($dir . '/' . $file_to_write,"w");
// a different way to write content into
// fwrite($file,"Hello World.");
fwrite($file, $content_to_write);
// closes the file
fclose($file);
// this will show the created file from the created folder on screen
include $dir . '/' . $file_to_write;
?>
</body>
</html>
我應該怎麼做
我認爲你必須追加數據,每次你在閱讀模式下打開文件並覆蓋現有的數據,而不是你已經將數據追加到文件上 –