script php pentru online/offline
Scris: Lun Iul 05, 2010
buna ziua, am gasit un si eu un cod pentru a imi arata cine este online si cine este offline pe site dar nu stiu cum sa imi dau seama daca ii trebuie bd sau daca ii trebuie care sunt campurile necesare si nu stiu cum sa il implementez! daca ma puteti sa ma ajutati cu niste sfaturi sau daca aveti ceva mai simplu decat asta. cu stima trif
Cod: SelectaĊ£i tot
<?php
class AppController extends Controller {
/*
*
* beforeRender() function will run on every visit of the website
*/
function beforeRender()
{
### UPDATE LAST VISIT ###
$online_offline_status = 0;
if ($this->Session->check('userId')==true){ // Checking for the SESSION - Proceed only if MEMBER/USER is logged in.
$this->loadModel('Member'); // Loading MEMBER Model
// UPDATE MEMBER VISIT TIME
$last_visit = date('Y-m-d H:i:s', time());
$this->Member->updateAll(array('Member.last_visit' => '"'.$last_visit.'"'), array('Member.id' => $this->Session->read('userId')));
// GET TIME DIFFERENCE
$member_last_visit = $this->Member->find('first', array('conditions' => array('Member.id' => $this->Session->read('userId'))));
$current_time = strtotime(date("Y-m-d H:i:s")); // CURRENT TIME
$last_visit = strtotime($member_last_visit['Member']['last_visit']); // LAST VISITED TIME
$time_period = floor(round(abs($current_time - $last_visit)/60,2)); //CALCULATING MINUTES
//IF YOU WANT TO CALCULATE DAYS THEN USER THIS
//$time_period = floor(round(abs($current_time - $last_visit)/60,2)/1440);
echo $time_period;
if ($time_period <= 10){
$online_offline_status = 1; // Means User is ONLINE
} else {
$online_offline_status = 0; // Means User is OFFLINE
}
}
$this->set('online_offline_status', $online_offline_status);
}//end beforeRender()
}
?>
<!-- IF USER IS OFFLINE -->
<?php if ($online_offline_status == 0){ ?>
<span style="color:#FF0000;">(Member/User is Offline)</span>
<!-- IF USER IS OFFLINE -->
<?php } else if ($online_offline_status == 1) {?>
<span style="color:#669900;">(Member/User is Online)</span>
<?php }?>