我尝试在SESSION目录的文件中存储多个会话值,但是当我尝试存储新值时,它会覆盖旧值并仅存储新值。
<?php
session_start();
?>
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<?php
$_SESSION['userName'] = 'nancy';
$_SESSION['emailAddress'] = 'nancy@gmail.com';
$_SESSION['userName'] = 'preeti';
$_SESSION['emailAddress'] = 'preeti@gmail.com';
$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>
我应该怎么做
答案 0 :(得分:1)
创建一个用户数组并将数据附加到其中:
$_SESSION['users'] = array();
$_SESSION['users'][] = array(
'name' => 'nancy',
'email' => 'nancy@gmail.com',
);
$_SESSION['users'][] = array(
'name' => 'preeti',
'email' => 'preeti@gmail.com',
);
答案 1 :(得分:0)
add values in session array so your values not overide like this
声明一个数组 $ _SESSION ['info'] = array();
$_SESSION['info'][] = array(
'fullname' => 'manish',
'email' => 'nancy@gmail.com',
);
$_SESSION['info'][] = array(
'fullname' => 'manish1',
'email' => 'nancy@gmail1.com',
);