Created
December 20, 2012 08:45
-
-
Save suziewong/4343872 to your computer and use it in GitHub Desktop.
DZX2.5 在线时长的bug 听说多个浏览器多开产生的 http://bbs.zjut.com/misc.php?mod=ranklist&type=member&view=onlinetime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
////dz_session.php | |
///174 行 | |
public static function updatesession() { | |
static $updated = false; | |
if(!$updated) { | |
global $_G; | |
/* $ulastactivity = authcode($_G['cookie']['ulastactivity'], 'DECODE'); | |
var_dump($ulastactivity); | |
exit;*/ | |
if($_G['uid']) { | |
if($_G['cookie']['ulastactivity']) { | |
$ulastactivity = authcode($_G['cookie']['ulastactivity'], 'DECODE'); | |
} else { | |
$ulastactivity = getuserprofile('lastactivity'); | |
dsetcookie('ulastactivity', authcode($ulastactivity, 'ENCODE'), 31536000); | |
} | |
} | |
///全局设置更新时长 | |
//$oltimespan 对应的值是后台全局--站点功能--其他--用户在线时间更新时长(分钟)的值。 | |
$oltimespan = $_G['setting']['oltimespan']; | |
//$lastolupdate = C::app()->session->var['lastolupdate']; | |
//将这行改成 | |
$lastolupdate = DB::result_first("select lastupdate from ".DB::table('common_onlinetime')." WHERE uid='$_G[uid]'"); | |
//如果是会员登录论坛,判断最近更新时间与当前时间的差大于用户在线时间更新时长时, | |
//会更新pre_common_onlinetime表(记录会员在线时间)里对应用户的对应字段的值,若没有对应用户,则添加一条记录。 | |
if($_G['uid'] && $oltimespan && TIMESTAMP - ($lastolupdate ? $lastolupdate : $ulastactivity) > $oltimespan * 60) { | |
if(!C::t('common_onlinetime')->update_onlinetime($_G['uid'], $oltimespan, $oltimespan, TIMESTAMP)) { | |
C::t('common_onlinetime')->insert(array( | |
'uid' => $_G['uid'], | |
'thismonth' => $oltimespan, | |
'total' => $oltimespan, | |
'lastupdate' => TIMESTAMP, | |
)); | |
} | |
C::app()->session->set('lastolupdate', TIMESTAMP); | |
} | |
//然后程序开始更新session(针对所有用户,包括未登录的游客),将session数据存到pre_common_session表里。 | |
foreach(C::app()->session->var as $k => $v) { | |
if(isset($_G['member'][$k]) && $k != 'lastactivity') { | |
C::app()->session->set($k, $_G['member'][$k]); | |
} | |
} | |
foreach($_G['action'] as $k => $v) { | |
C::app()->session->set($k, $v); | |
} | |
C::app()->session->update(); | |
//最后根据用户最近的更新的时间,将计算出的用户在线时间,更新到pre_common_member_count表 | |
//(统计用户记录信息表)里,我们看到的在线时间就是从此表里读取出来的, | |
//并且记录当前时间为用户最近活跃的时间。(注意:pre_common_member_count表中的在线时间是每12个小时更新一次) | |
if($_G['uid'] && TIMESTAMP - $ulastactivity > 21600) { | |
if($oltimespan && TIMESTAMP - $ulastactivity > 43200) { | |
$onlinetime = C::t('common_onlinetime')->fetch($_G['uid']); | |
C::t('common_member_count')->update($_G['uid'], array('oltime' => round(intval($onlinetime['total']) / 60))); | |
} | |
dsetcookie('ulastactivity', authcode(TIMESTAMP, 'ENCODE'), 31536000); | |
C::t('common_member_status')->update($_G['uid'], array('lastip' => $_G['clientip'], 'lastactivity' => TIMESTAMP, 'lastvisit' => TIMESTAMP)); | |
} | |
$updated = true; | |
} | |
return $updated; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function update_onlinetime($uid, $total, $thismonth, $lastupdate) { | |
if(($uid = intval($uid))) { | |
DB::query("UPDATE ".DB::table('common_onlinetime')." | |
SET total=total+'$total', thismonth=thismonth+'$thismonth', lastupdate='".$lastupdate."' WHERE ".DB::field($this->_pk, $uid)); | |
return DB::affected_rows(); | |
} | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment