我希望显示所有与会话输入的内容..但只有一个显示..我想显示过去的结果也是会话..这里我的代码;
<form method="post">
isim gir
<input type="text" name="isim" id="isim[]" />
<input type="submit" name="gir" value="sözler" />
</form>
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_POST["gir"])){
$isim=$_POST["isim"];
echo $_SESSION["name"]=$isim;
}
?>
答案 0 :(得分:0)
session_start()
应放在代码的第一位,如果你想在$_SESSION
数组中打印所有内容,你可以这样做:
echo "<pre>",print_r($_SESSION),"</pre>";
答案 1 :(得分:0)
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$sanitize_post = filter_input_array(INPUT_POST);
if(!empty($sanitize_post)){
$_SESSION['input'][] = $sanitize_post;
}
function reducer($acc, $val)
{
return $acc .= $val;
}
function allUserInput()
{
# Extract user input from session.
if(empty($_SESSION)) return;
foreach ($_SESSION['input'] as $key) {
echo "<li>".array_reduce($key, 'reducer', '')."</li>";
}
}
?>
<form method="POST">
<ul><?php echo allUserInput(); ?></ul>
<input type="text" name="isim" id="isim" />
<input type="submit" name="gir" value="sözler" />
</form>
答案 2 :(得分:0)
创建一个search_history
会话变量,其中包含所有搜索的数组。
if (!isset($_SESSION['search_history'])) {
$_SESSION['search_history'] = array();
}
if (isset($_POST['gir'])) {
$isim = $_POST['isim'];
$_SESSION['search_history'][] = $isim;
}