Feature User Online Page for Dabr (Twitter Client)


How to make it?

Create a file (eg: count.php):

code:

<?php
error_reporting(E_ERROR | E_PARSE);
$dataFile = "onlineusers.txt";
if (user_is_authenticated()) {
$user = user_current_username();
}
// this is the time in **minutes** to consider someone online before removing them from our file
// berapa menit tenggang waktu yg dibutuhkan untuk tahu user masih online atau tidak.

$sessionTime = 5;
if(!file_exists($dataFile)) {
$fp = fopen($dataFile, "w+");
fclose($fp);
}
$users = array();
$onusers = array();
// check up
$fp = fopen($dataFile, "r");
flock($fp, LOCK_SH);
while(!feof($fp)) {
$users[] = rtrim(fgets($fp, 32));
}
flock($fp, LOCK_UN);
fclose($fp);
// clean up
$x = 0;
$alreadyIn = FALSE;
foreach($users as $key => $data) {
list(,$lastvisit) = explode("|", $data);
if(time() – $lastvisit >= $sessionTime * 60) {
$users[$x] = "";
} else {
if(strpos($data, $user) !== FALSE) {
$alreadyIn = TRUE;
$users[$x] = "$user|" . time(); //updating
}
}
$x++;
}
if($alreadyIn == FALSE) {
$users[] = "$user|" . time();
}
// write up
$fp = fopen($dataFile, "w+");
flock($fp, LOCK_EX);
$i = 0;
foreach($users as $single) {
if($single != "") {
fwrite($fp, $single . "\r\n");
$i++;
}
}
flock($fp, LOCK_UN);
fclose($fp);
?>

We have to include the count.php file to all the accessible pages.
In dabr, usually common/theme.php -> function theme_page()

code:

if (user_is_authenticated()) {
require_once("count.php");
}
echo ‘</body>
</html>’;
exit();

Create another file (eg: online.php). This file is to show the list of the online users.

Code:

<?php
$myFile = "onlineusers.txt";
$fsc = file($myFile);
$lines = count(file($myFile));
$content = "<div>".$lines." Online Users:<br />";
foreach($fsc as $line) {
$array = explode("|", $line);
$content .= $array[0] ."</a><br />";
}
$content .= "</div>";

?>

And edit the index.php file to add this line

code:

<?php
menu_register(array (
……
‘online’ => array (
‘security’ => true,
‘callback’ => ‘online_page’,
),
….
));
?>

Still at the index.php file just before the browser_detect(); add this line:

code:

<?php
function online_page() {
require_once("online.php");
theme(‘page’, ‘Online Users’, $content);
}
?>

And don’t forget to chmod 777 the file onlineusers.txt…

Do not forget to visit & use Twitter Client from us at the address www.imorv.comūüôā

@fays_lee

5 Tanggapan

  1. bisa djelasn gk mksud dri
    “And don‚Äôt forget to chmod 777
    the file onlineusers.txt‚Ķ” ???

  2. imorv menggunakan kwestion..
    klo yg mobile pake dabr

  3. Mas, saya mau script seperti imorv.com
    kira-kira brapa biayanya sama setingnya bls ke email aja mas

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: