PHP语句限制发帖 注册用户名中的分四种,1,个人用户。2,免费中介,3,高级中介,4,待审中介。个人用户每天可以发布4条信息,免费中介可以每天发布10条信息,高级中介不限,请问怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 系统预设常量$max_records = array('a' => 4, 'b' => 10);用户信息:$uid #用户标识$type #用户类型以使用缓存Memcache为例$default_host = '127.0.0.1';$default_port = 11211;function getCache($host, $port) { $cache = new Memcache(); $cache->connect($host, $port); return $cache;}function canRelease($uid, $type, $cache = NULL) { static $max_records = array('a' => 4, 'b' => 10); global $default_host, $default_port; if(!isset($max_records[$type])) return true; $max_record = $max_records[$type]; $cache or ($cache = getCache($default_host, $default_port)); $today = date('Ymd'); $current_record = $cache->get("$uid/releasecount/$today"); return $current_record < $max_record;}function incrementCount($uid, $cache = NULL) { $today = date('Ymd'); $now = time(); $today_last_time = strtotime(date('Ymd')); $life_cycle = $today_last_time - $now; $cache or ($cache = getCache($default_host, $default_port)); $original_record = $cache->get("$uid/releasecount/$today"); return $cache->set("$uid/releasecount/$today", ++ $original_record);}在发布信息的时候 首先用canRelease检测一下发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口. #mail: [email protected]#blog: http://blog.csdn.net/lgg201#有不足之处欢迎交流, 谢谢系统预设常量$max_records = array('a' => 4, 'b' => 10);用户信息:$uid #用户标识$type #用户类型以使用缓存Memcache为例$default_host = '127.0.0.1';$default_port = 11211;function getCache($host, $port) { $cache = new Memcache(); $cache->connect($host, $port); return $cache;}function canRelease($uid, $type, $cache = NULL) { static $max_records = array('a' => 4, 'b' => 10); global $default_host, $default_port; if(!isset($max_records[$type])) return true; $max_record = $max_records[$type]; $cache or ($cache = getCache($default_host, $default_port)); $today = date('Ymd'); $current_record = $cache->get("$uid/releasecount/$today"); return $current_record < $max_record;}function incrementCount($uid, $cache = NULL) { $today = date('Ymd'); $now = time(); $today_last_time = strtotime(date('Ymd')); $life_cycle = $today_last_time - $now; $cache or ($cache = getCache($default_host, $default_port)); $original_record = $cache->get("$uid/releasecount/$today"); return $cache->set("$uid/releasecount/$today", ++ $original_record);}在发布信息的时候 首先用canRelease检测一下发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口. #mail: [email protected]#blog: http://blog.csdn.net/lgg201#有不足之处欢迎交流, 谢谢#不好意思, 上面的少了设置值的失效时间#系统预设常量$max_records = array('a' => 4, 'b' => 10);#用户信息:$uid #用户标识$type #用户类型#以使用缓存Memcache为例$default_host = '127.0.0.1';$default_port = 11211;function getCache($host, $port) { $cache = new Memcache(); $cache->connect($host, $port); return $cache;}function canRelease($uid, $type, $cache = NULL) { static $max_records = array('a' => 4, 'b' => 10); global $default_host, $default_port; if(!isset($max_records[$type])) return true; $max_record = $max_records[$type]; $cache or ($cache = getCache($default_host, $default_port)); $today = date('Ymd'); $current_record = $cache->get("$uid/releasecount/$today"); return $current_record < $max_record;}function incrementCount($uid, $cache = NULL) { $today = date('Ymd'); $now = time(); $today_last_time = strtotime(date('Ymd')); $life_cycle = $today_last_time - $now; $cache or ($cache = getCache($default_host, $default_port)); $original_record = $cache->get("$uid/releasecount/$today"); #下面增加life_cycle是为了到第二天时候把数据给清理了, 这个时间可以根据需求设长点, 因为第二天key不一样了, 不会影响正确性 return $cache->set("$uid/releasecount/$today", ++ $original_record, NULL, $life_cycle);}#在发布信息的时候 #首先用canRelease检测一下#发布完信息之后, 调用incrementCount增加一下计数#Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口. 各位能给个简单的方法吗?比如根据用户ID统计用户一天的发帖量 如果达到一定数量 就提示一下 比如 select count(*) as title from table where addtime = 当天的时间 and uid=当前登录用户id根据统计出来的title的来计算 求助一个分页问题 PHP的线程安全问题 关于php项目里一个文件的作用,请高人指点 apache上设置程序不能跨网站引用和读取程序是哪里? 看看这个函数的含义 php 中 pack 和unpack的问题 我想问下关于PHP的模板引擎问题!!!! supplied argument is not a valid OCI8-Statement resource 奇怪问题!解决了我给高分 微信chooseImage接口部分机型选择图片跳转到其他页面 字符串转换,JAVA代码转PHP代码,提供源码,高手都来拿分。 为什么报错啊?请大家师傅看一下
$max_records = array('a' => 4, 'b' => 10);用户信息:
$uid #用户标识
$type #用户类型以使用缓存Memcache为例
$default_host = '127.0.0.1';
$default_port = 11211;
function getCache($host, $port) {
$cache = new Memcache();
$cache->connect($host, $port);
return $cache;
}
function canRelease($uid, $type, $cache = NULL) {
static $max_records = array('a' => 4, 'b' => 10);
global $default_host, $default_port;
if(!isset($max_records[$type])) return true;
$max_record = $max_records[$type];
$cache or ($cache = getCache($default_host, $default_port));
$today = date('Ymd');
$current_record = $cache->get("$uid/releasecount/$today");
return $current_record < $max_record;
}
function incrementCount($uid, $cache = NULL) {
$today = date('Ymd');
$now = time();
$today_last_time = strtotime(date('Ymd'));
$life_cycle = $today_last_time - $now;
$cache or ($cache = getCache($default_host, $default_port));
$original_record = $cache->get("$uid/releasecount/$today");
return $cache->set("$uid/releasecount/$today", ++ $original_record);
}在发布信息的时候
首先用canRelease检测一下
发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
#mail: [email protected]
#blog: http://blog.csdn.net/lgg201
#有不足之处欢迎交流, 谢谢系统预设常量
$max_records = array('a' => 4, 'b' => 10);用户信息:
$uid #用户标识
$type #用户类型以使用缓存Memcache为例
$default_host = '127.0.0.1';
$default_port = 11211;
function getCache($host, $port) {
$cache = new Memcache();
$cache->connect($host, $port);
return $cache;
}
function canRelease($uid, $type, $cache = NULL) {
static $max_records = array('a' => 4, 'b' => 10);
global $default_host, $default_port;
if(!isset($max_records[$type])) return true;
$max_record = $max_records[$type];
$cache or ($cache = getCache($default_host, $default_port));
$today = date('Ymd');
$current_record = $cache->get("$uid/releasecount/$today");
return $current_record < $max_record;
}
function incrementCount($uid, $cache = NULL) {
$today = date('Ymd');
$now = time();
$today_last_time = strtotime(date('Ymd'));
$life_cycle = $today_last_time - $now;
$cache or ($cache = getCache($default_host, $default_port));
$original_record = $cache->get("$uid/releasecount/$today");
return $cache->set("$uid/releasecount/$today", ++ $original_record);
}在发布信息的时候
首先用canRelease检测一下
发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
#mail: [email protected]
#blog: http://blog.csdn.net/lgg201
#有不足之处欢迎交流, 谢谢
#不好意思, 上面的少了设置值的失效时间#系统预设常量
$max_records = array('a' => 4, 'b' => 10);#用户信息:
$uid #用户标识
$type #用户类型#以使用缓存Memcache为例
$default_host = '127.0.0.1';
$default_port = 11211;
function getCache($host, $port) {
$cache = new Memcache();
$cache->connect($host, $port);
return $cache;
}
function canRelease($uid, $type, $cache = NULL) {
static $max_records = array('a' => 4, 'b' => 10);
global $default_host, $default_port;
if(!isset($max_records[$type])) return true;
$max_record = $max_records[$type];
$cache or ($cache = getCache($default_host, $default_port));
$today = date('Ymd');
$current_record = $cache->get("$uid/releasecount/$today");
return $current_record < $max_record;
}
function incrementCount($uid, $cache = NULL) {
$today = date('Ymd');
$now = time();
$today_last_time = strtotime(date('Ymd'));
$life_cycle = $today_last_time - $now;
$cache or ($cache = getCache($default_host, $default_port));
$original_record = $cache->get("$uid/releasecount/$today");
#下面增加life_cycle是为了到第二天时候把数据给清理了, 这个时间可以根据需求设长点, 因为第二天key不一样了, 不会影响正确性
return $cache->set("$uid/releasecount/$today", ++ $original_record, NULL, $life_cycle);
}#在发布信息的时候
#首先用canRelease检测一下
#发布完信息之后, 调用incrementCount增加一下计数#Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
比如
select count(*) as title from table
where addtime = 当天的时间 and uid=当前登录用户id
根据统计出来的title的来计算