当前位置: 编程技术>php
本页文章导读:
▪php 使用COOKIE制作浏览记录 - assassin0905 文件1 cookieHistory.class.php<?php/** *使用COOKIE 制作网站浏览记录 *by threemore */class HistoryCookie {var $times =""; //记录COOKIE保存时间var $cookiename = 'History_cookie'; //COOKIE名称var $counts = 5;function __construct.........
▪分享一个检测用户是否用手机(Mobile)访问网站的 PHP 类 - naledao 有一个基于MIT License协议开源的PHP程序http://code.google.com/p/php-mobile-detect/程序就是一个文件,下载之后直接引用就可以。使用方法:<?phpinclude("Mobile_Detect.php");$detect = new Mobile_Detect(); if ($det.........
▪php 删除目录下N分钟前创建的所有文件 - 漫步在互联网 php中删除目录下N分钟前创建的所有文件。代码:<?php/*** 删除当DIR路径下N分钟前创建的所有文件* 整理: www.*///delfile("upload",10);function delfile($dir,$n) {if(is_dir($dir)){if($dh=opendir($dir)){while (false !==.........
[1]php 使用COOKIE制作浏览记录 - assassin0905
文件1 cookieHistory.class.php
<?php
/**
*使用COOKIE 制作网站浏览记录
*by threemore
*/
class HistoryCookie {
var $times =""; //记录COOKIE保存时间
var $cookiename = 'History_cookie'; //COOKIE名称
var $counts = 5;
function __construct($name="",$times = '',$counts) {
if(!empty($times)) $this->times = time()+$times;
if(!empty($name)) $this->cookiename = $name;
if(!empty($counts)) $this->counts = $counts;
}
//保存记录到COOKIE中
public function getData($data) {
$historydate = array();
$historydate[] = $data;
//unset($_COOKIE[$this->cookiename]);
if(isset($_COOKIE[$this->cookiename])) {
$new_history = stripslashes($_COOKIE[$this->cookiename]);
$new = unserialize($new_history);
if(count($new) > ($this->counts-1)) return unserialize(stripslashes($_COOKIE[$this->cookiename]));
foreach ($new as $key => $value) {
if(!in_array($value,$historydate)) {
$historydate[] =$value;
}
}
$savedate = serialize($historydate);
setcookie($this->cookiename,$savedate,time()+$this->times);
}else {
$savedate= serialize($historydate);
setcookie($this->cookiename,$savedate,$this->times);
}
return unserialize(stripslashes($_COOKIE[$this->cookiename]));
}
//销毁历史记录
public function Destroy() {
unset($_COOKIE[$this->cookiename]);
}
}
?>
/**
*使用COOKIE 制作网站浏览记录
*by threemore
*/
class HistoryCookie {
var $times =""; //记录COOKIE保存时间
var $cookiename = 'History_cookie'; //COOKIE名称
var $counts = 5;
function __construct($name="",$times = '',$counts) {
if(!empty($times)) $this->times = time()+$times;
if(!empty($name)) $this->cookiename = $name;
if(!empty($counts)) $this->counts = $counts;
}
//保存记录到COOKIE中
public function getData($data) {
$historydate = array();
$historydate[] = $data;
//unset($_COOKIE[$this->cookiename]);
if(isset($_COOKIE[$this->cookiename])) {
$new_history = stripslashes($_COOKIE[$this->cookiename]);
$new = unserialize($new_history);
if(count($new) > ($this->counts-1)) return unserialize(stripslashes($_COOKIE[$this->cookiename]));
foreach ($new as $key => $value) {
if(!in_array($value,$historydate)) {
$historydate[] =$value;
}
}
$savedate = serialize($historydate);
setcookie($this->cookiename,$savedate,time()+$this->times);
}else {
$savedate= serialize($historydate);
setcookie($this->cookiename,$savedate,$this->times);
}
return unserialize(stripslashes($_COOKIE[$this->cookiename]));
}
//销毁历史记录
public function Destroy() {
unset($_COOKIE[$this->cookiename]);
}
}
?>
文件二 history.php
<?php
require_once 'cookieHistory.class.php';
ob_start();//打开缓冲区
$history = new HistoryCookie('cookiename',10000);
$data['id'] = $_GET['id'];
$data['name'] = $_GET['name'];
$cookiedate = $history->getData($data);
echo "<pre>";
print_r($cookiedate);
?>
require_once 'cookieHistory.class.php';
ob_start();//打开缓冲区
$history = new HistoryCookie('cookiename',10000);
$data['id'] = $_GET['id'];
$data['name'] = $_GET['name'];
$cookiedate = $history->getData($data);
echo "<pre>";
print_r($cookiedate);
?>
程序流程:
本文链接:http://www.cnblogs.com/threemore/p/cookies.html,转载请注明。
[2]分享一个检测用户是否用手机(Mobile)访问网站的 PHP 类 - naledao
有一个基于MIT License协议开源的PHP程序
http://code.google.com/p/php-mobile-detect/
程序就是一个文件,下载之后直接引用就可以。
使用方法:
<?php
include("Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
// any mobile platform
echo 'isMobile';
}
else{
echo 'isPC';
}
?>
include("Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
// any mobile platform
echo 'isMobile';
}
else{
echo 'isPC';
}
?>
本文链接:http://www.cnblogs.com/naledao/p/3247836.html,转载请注明。
[3]php 删除目录下N分钟前创建的所有文件 - 漫步在互联网
php中删除目录下N分钟前创建的所有文件。
代码:
<?php
/**
* 删除当DIR路径下N分钟前创建的所有文件
* 整理: www.
*/
//delfile("upload",10);
function delfile($dir,$n)
{
if(is_dir($dir))
{
if($dh=opendir($dir))
{
while (false !== ($file = readdir($dh)))
{
if($file!="." && $file!="..")
{
$fullpath=$dir."/".$file;
if(!is_dir($fullpath))
{
//$filedate=date("Y-m-d", filemtime($fullpath));
$filedate=date("Y-m-d h:i:s", filemtime($fullpath));
//$d1=strtotime(date("Y-m-d"));
$d1=strtotime(date("Y-m-d h:i:s"));
$d2=strtotime($filedate);
//$Days=round(($d1-$d2)/3600/24);
$Days=round(($d1-$d2)/60);
if($Days>$n)
unlink($fullpath); ////删除文件
}
}
}
}
closedir($dh);
}
}
?>
/**
* 删除当DIR路径下N分钟前创建的所有文件
* 整理: www.
*/
//delfile("upload",10);
function delfile($dir,$n)
{
if(is_dir($dir))
{
if($dh=opendir($dir))
{
while (false !== ($file = readdir($dh)))
{
if($file!="." && $file!="..")
{
$fullpath=$dir."/".$file;
if(!is_dir($fullpath))
{
//$filedate=date("Y-m-d", filemtime($fullpath));
$filedate=date("Y-m-d h:i:s", filemtime($fullpath));
//$d1=strtotime(date("Y-m-d"));
$d1=strtotime(date("Y-m-d h:i:s"));
$d2=strtotime($filedate);
//$Days=round(($d1-$d2)/3600/24);
$Days=round(($d1-$d2)/60);
if($Days>$n)
unlink($fullpath); ////删除文件
}
}
}
}
closedir($dh);
}
}
?>
本文链接:http://www.cnblogs.com/cfinder010/p/3249746.html,转载请注明。
最新技术文章: