douni1396 2016-07-11 19:47
浏览 26

基于php中的cookie在喜欢的页面中保存多个页面

hi I am designing a real estate website i have many ads in my website and when user click on a certain ad it goes to another page viewmore.php which gives user more details about that certain ad.
Now as you see in viewmore.php file I save ad's id in cookies and send ad's id to the favorite page and user can review that post any time he or she wants in favorite page.
now the problem
consider a user visit two post
viewmore.php?id=10
and
viewmore.php?id=7
in this case he or she wants to see both ads in favorite page not, only the last one. in my code it just shows the last add with id=7 how can i change my codeso that previous add does not disappear. any idea? thank u
viewmore.php

<?php
$ID = is_numeric($_GET['ID']) ? $_GET['ID'] : 1;

$cookie_name = "favoritepost";

if ( isset($_COOKIE[$cookie_name]) ) {
    $kookie = unserialize($_COOKIE[$cookie_name]);
} else {
    $kookie = array();
}
if ( ! in_array($ID, $kookie) ) {
    $kookie[] = $ID;
}

setcookie($cookie_name, serialize($kookie), time() + (86400 * 30), "/"); // 86400 = 1 day
?>
<html>

<!doctype html>
<html>
<body>
<?php
$cookie_name = "favoritepost";
include("config.php");
if ( ! isset($_COOKIE[$cookie_name]) ) {
    echo 'NO COOKIE SET';
    exit;
}

$kookie = unserialize($_COOKIE[$cookie_name]);
$ID = $kookie[count($kookie)-1];
$result = mysqli_query($connect,"SELECT * FROM $db_table WHERE idhome = $ID");

$row = mysqli_fetch_array($result):
$price=$row['price'];
$rent=$row['rent'];
$room=$row['room'];
$date=$row['date'];

echo"price";
echo"room";
echo"date";
?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致