php 怎么清除历史

藏色散人
发布: 2021-12-14 09:23:02
原创
2156人浏览过
php清除历史的方法:1、创建一个PHP示例文件;2、通过setcookie设置cookie;3、通过“echo 'clear';”等diam清除历史记录即可。

php 怎么清除历史

本文操作环境:Windows7系统,PHP7.4版,Dell G3电脑。

php 怎么清除历史?

php简单实现cookie的历史记录及清除历史记录功能

代码如下:

立即学习PHP免费学习笔记(深入)”;

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQT</title>
<style>div{ width:300px;height:400px; background:#CFF; padding:20px}</style>
</head>
<?php
//用于测试的文档
$all_data = array(
1 => array('1:标题1','内容1……'),
2 => array('2:标题2','内容2……'),
3 => array('3:标题3','内容3……'),
4 => array('4:标题4','内容4……'),
);
 
$id=isset($_GET['id'])?$_GET['id']:1;
 
//判断有无设置action
$action = isset($_GET['action'])?$_GET['action']:$id; 
if($action=='clear'){
//清空cookie
setcookie('history','',time()-3600);
//数组清空
$his=array();
}else{
if(!isset($_COOKIE['history'])){
$his[]=$id;
}else{
$his=explode('|',$_COOKIE['history']);
array_unshift($his, $id);
$his=array_unique($his);
if(count($his)>4){
array_pop($his);
}
}
}
setcookie('history',implode('|', $his));
?>
 
<body>
<div>
<form >
<table>
    <tr><td><?php echo $all_data[$id][0]?></td></tr>
    <tr><td><?php echo $all_data[$id][1]?></td></tr>
    <tr>
    <td>  
        <p><a href="04.php?id=<?php echo $id-1==0?4:$id-1;?>">上一页</a></p>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/xiazai/code/9771">
                            <img src="https://img.php.cn/upload/webcode/000/000/012/175991040345864.jpg" alt="百堂数字点卡程序">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/xiazai/code/9771">百堂数字点卡程序</a>
                            <p>商品分类、分级,可以销售各种游戏、娱乐卡,甚至电话卡等1、方便简洁的购卡、显示卡号流程 2、自动从预付款中扣除金额,自动显示卡号等3、帐户余额显示、提醒4、历史订单管理、浏览5、会员密码加密,增强系统的安全性6、商品订单明细清晰,应付款项清楚7、后台处理提供商品统计、分析能力,帮助决策8、商品显示顺序可自己设定,如按价格倒序、升序,按购买量升序、倒序等等9、即时显示卡号或密码,零等候时间。</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="百堂数字点卡程序">
                                <span>0</span>
                            </div>
                        </div>
                        <a href="/xiazai/code/9771" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="百堂数字点卡程序">
                        </a>
                    </div>
                
        </td>
        <td>
         <p><a href="04.php?id=<?php echo $id+1==5?1:$id+1;?>">下一页</a></p>
        </td>
    </tr>
<tr>
     <td>
        <p>浏览历史</p>
     </td>
         <td>
        <a href="04.php?action=<? echo 'clear';?>">清除记录</a>
     </td>
    </tr>
        <tr>
         <ul>
         <td>
            <?php foreach($his as $v) {?>
            <li><a href="04.php?id=<? echo $v;?>"><?php echo $all_data[$v][0] ; ?></a></li>
            <?php } ?>
         </td>
</ul>
        </tr>
    </table>
</form>
</div>
</body>
</html>
登录后复制

复制粘贴即可运行~

推荐学习:《PHP视频教程

以上就是php 怎么清除历史的详细内容,更多请关注php中文网其它相关文章!

相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号