我希望将最后 3 次搜索保存在 Cookie 中并显示在“< p>”标签中。这是我的 HTML 代码:
<form class="Dform" method="POST" action="index.php">
<input type="text" name="search" value="">
<input type="submit" name="" value="Search">
</form>
我只设法显示了以前的搜索,但我不知道如何执行前 2 个搜索,这是我的 php 代码:
<?php
if (!empty($_POST['search']))
{
setcookie('PreviousSearch', $_POST['search'], time()+60*60,'',localhost);
}
?>
<?php
$r1 = htmlspecialchars($_COOKIE['PreviousSearch']);
echo '<p> Previous search (1) : '.$r1.'</p>';
?>