ecshop中的浏览历史
来源:互联网 发布:xboxone运行windows 编辑:程序博客网 时间:2024/06/11 21:06
今天看了看 ecshop 中的浏览历史的代码,分析了一下,有什么不对的地方,欢迎指出纠正,不胜感激…
不难看出,在你每次浏览一件商品的同时,会在左侧中记录您的浏览记录,在ecshop中是通过cookie来记录的, 在goods.php里可以查到如下代码:
if (!empty($_COOKIE['ECS']['history'])){ $history = explode(',', $_COOKIE['ECS']['history']); array_unshift($history, $goods_id); $history = array_unique($history); while (count($history) > $_CFG['history_number']) { array_pop($history); } setcookie('ECS[history]', implode(',', $history), gmtime() + 3600 * 24 * 30);}else{ setcookie('ECS[history]', $goods_id, gmtime() + 3600 * 24 * 30);}
每一次浏览,都会记录$good_id(商品的id),放到cookie里。
在模版里goods.dwt里是引用了<!-- #BeginLibraryItem "/library/history.lbi" --><!-- #EndLibraryItem -->
在history.lbi里可以看到 {insert name=’history’}, 基本上学过smarty的都知道,这是局部不缓冲用到的,那么它肯定存在一个方法: insert_history()
,果然,在lib_insert.php
中找到了。其实lib_insert.php
就是一个动态内容函数库。
function insert_history(){ $str = ''; if (!empty($_COOKIE['ECS']['history'])) { $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id'); $sql = 'SELECT goods_id, goods_name FROM ' . $GLOBALS['ecs']->table('goods') ." WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0"; $query = $GLOBALS['db']->query($sql); $res = array(); while ($row = $GLOBALS['db']->fetch_array($query)) { $res[$row['goods_id']] = $row; } $tureorder = explode(',', $_COOKIE['ECS']['history']); foreach ($tureorder AS $key => $val) { $goods_name = htmlspecialchars($res[$val]['goods_name']); if ($goods_name) { $short_name = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($goods_name, $GLOBALS['_CFG']['goods_name_length']) : $goods_name; $str .= '<li><a href="' . build_uri('goods', array('gid' => $val), $goods_name). '" title="' . $goods_name . '">' . $short_name . '</a></li>'; } } } return $str;}
其实该函数返回的字符串就是history.lbi里的所需内容,需要说明一下的是像代码中类似 $_CFG['history_number']
,一般是系统定义的常量或是数据库中保存的字段,查了一下发现是在 ecs_shop_config
表里。剩下的就是看一下代码,怎么通过商品的id ,获取商品的信息了。不再多说,提醒一下,上面用到了几个针对数据函数,如array_unshift,array_unique
还是经常遇到的,顺便巩固一下。
0 0
- ecshop中的浏览历史
- ecshop中的浏览历史
- ecshop中的浏览历史
- ecshop中的浏览历史代码分析
- 浏览历史
- 清除firefox浏览器历史浏览中的某一项
- 获取用户浏览历史
- 浏览历史页面
- 实现浏览历史查看
- Ecmall 商品浏览历史
- cookie 记住浏览历史
- 返回历史浏览位置
- 浏览历史的实现
- 显示商品历史浏览记录
- cookie来做浏览历史
- Cookies 实现 商品历史浏览
- cookie---照片浏览历史显示
- 在ECSHOP首页增加一个浏览排行
- PHP构造方法&析构函数
- Thinkpad L440 安装固态硬盘和加装内存条
- 七. 界面编程--Windows编程课程学习笔记
- UIControl以及 响应链
- 2-6关闭窗口
- ecshop中的浏览历史
- poj 3617
- Modbus-RTU通讯协议中CRC校验码的计算步骤
- Strlcpy和strlcat——一致的、安全的字符串拷贝和串接函数
- iOS coredata的使用及版本升级
- SHA:安全散列算法 .
- 获取jar包中的目录及文件
- Integer Break 找到乘积最大的拆分
- 搜索主元素