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>
我应该怎么做
我认为你必须追加数据,每次你在阅读模式下打开文件并覆盖现有的数据,而不是你已经将数据追加到文件上 –