You are on page 1of 4

www.hkvforums.

com
Skip to content

Board index ‹ PHPMaker ‹ User Submitted Tips (PHPMaker)


Change font size
Print view

FAQ
Register
Login

Connected Users (v8)


Post a reply
6 posts • Page 1 of 1

Connected Users (v8)

by ExonDepot » Thu Jul 21, 2011 12:22 am

This tip allows getting the list of users currently connected to a PHPMaker application.
You must be using the User Profile option and field in the database.

Just declare a view, over the User Table, using a Where clause such as:

SELECT * FROM users WHERE (`users`.`Profile` LIKE '%s:9:"SessionID";s:26:%')

You can replace the SELECT * by SELECT <some columns> if you don't need all table columns.
this query/view will extract all users that are currently connected (active sessions).

Comments are very welcome.

Regards...JLP

ExonDepot

Top

Re: Connected Users (v8)

by escalante » Thu Aug 25, 2011 3:07 am

profile field is available in V7 so it works for me too


i don't know yet how i gonna use it, but im sure its going to be useful... thanks!!!

escalante

Top

Re: Connected Users (v8)

by shahparz » Fri Dec 16, 2011 3:36 pm

i am trying to set this issue but facing this problem. When a user is logged in the profile column filled with :
a:1:{s:15:"LoginRetryCount";i:0;}

but not with the code you mentioned. I am using Version 8.0.3.

Can u please explain a little bit about this problem.

Regards

shahparz

Top

Re: Connected Users (v8)


by ddominguez » Fri Feb 10, 2012 12:13 pm
excellent, bro how i can to save the current session into a database??

ddominguez

Top

Re: Connected Users (v8)


by adim » Sun Jun 17, 2012 7:30 am

There is another way to see active users conected.


You need the following:
1. We will make a new table into your database, lets say: users_online with following definition
DROP TABLE IF EXISTS `mydatabase`.`users_online`;
CREATE TABLE `mydatabase`.`users_online` (
`timestamp` int(15) NOT NULL DEFAULT '0',
`ip` varchar(40) NOT NULL,
`file` varchar(100) NOT NULL,
`username` varchar(32) DEFAULT NULL,
`updated` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `username` (`username`)
) ENGINE=MEMORY DEFAULT CHARSET=utf8;

We make it MEMORY table because there will be a lot of insert/deletes in this table and depending of how many users will be connected, you dont
want to put overhead on your HDD.

2. We need a page that will be loaded with every time together with any page on your site, like header or footer. Lets say header.php, so modify your
header.php and put this code somewhere:

<?php
// Display no of users online to Administrator //

$timeoutseconds = 600; // = 10 minutes (this is the timeout set in config file | after this period my app will automatically logout user, you can put
here any period)

$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

if (!isset($_SESSION["mydatabase_status_UserName"])) $_SESSION["mydatabase_status_UserName"] = "Unknown User"; // this is set


automatically by phpmkr on login time

$insert = "INSERT INTO users_online VALUES


('".$timestamp."','".$_SERVER["REMOTE_ADDR"]."','".$_SERVER["PHP_SELF"]."','".$_SESSION["mydatabase_status_UserName"]."',NOW())";
$resultIns = $conn->execute($insert);
if(!($resultIns)) {
print "Useronline Insert Failed > ";
}
$delete = "DELETE FROM users_online WHERE timestamp < '".$timeout."'";
$resultDel = $conn->execute($delete);
if(!($resultDel)) {
print "Useronline Delete Failed > ";
}

$select = "SELECT timestamp FROM users_online GROUP BY username ";


$resultSel = $conn->execute($select);
if(!($resultSel)) {
print "Useronline Select Error > ";
}
$user = $resultSel->RecordCount();

$resultSel->close();

//Display only to Administrators


if (IsSysAdmin()) {
if($user == 1) {
print("<b style=\"color:red;\">".$user."</b> user online (You)\n");
} else {
print("<b style=\"color:red;\">".$user."</b> users online &nbsp;|&nbsp;<a href=\"home.php\" ><img src=\"images/view-online-users.png\"
width=\"16px\" height=\"16px\" border=\"0\" align=\"absmiddle\" title=\"View online users\" /></a>\n");
}
} // end if Admins

?>

It shows you how many users are conected on your site within a timespan of $timeout (in our case 10 minutes is sufficient).
I've also made a new page to show me their usernames.
So make a new page called home.php
I made this page available only to Administrator too. Code for this page can be:

<?php
if (session_id() == "") session_start(); // Initialize Session data

include_once "ewcfg8.php";
include_once "ewmysql8.php";
include_once "phpfn8.php";
include_once "usersinfo.php";
include_once "userfn8.php";
?>
<html>
<body>

<h2>USERS ONLINE</h2>
<p>
See users currently online (timespan - 300s = 5 min).
</p>
<span style="font-size:small;">
<?php
$select = "SELECT uo.username, uo.file FROM users_online uo GROUP BY uo.username ";
$result = $conn->execute($select);
echo "Currently online users: <br>";

while(!$result->EOF) {
echo "&nbsp;|&nbsp;".$result->fields[0] . "&nbsp;(".$result->fields[1].")&nbsp;<br>";
$result->MoveNext();
} //end while
?>
</span>
<hr />
</body>
</html>

That's all, hope this help.


Enjoy.
adim

adim

Top

Re: Connected Users (v2019)


by saleh » Mon Jan 28, 2019 11:11 am

hello

I tried the code but it does not work

include_once "ewcfg8.php";
include_once "ewmysql8.php";
include_once "phpfn8.php";
include_once "usersinfo.php";
include_once "userfn8.php";

Change to:
include_once "ewcfg15.php";
include_once "ewmysql15.php";
include_once "phpfn15.php";
include_once "usersinfo.php";
include_once "userfn15.php";

But two files do not exist:


ewmysql15.php
usersinfo.php

Notice: Undefined variable: RELATIVE_PATH in C:\xampp\htdocs\alamana\ewcfg15.php on line 64

Notice: Undefined variable: RELATIVE_PATH in C:\xampp\htdocs\alamana\ewcfg15.php on line 203

Notice: Undefined variable: RELATIVE_PATH in C:\xampp\htdocs\alamana\ewcfg15.php on line 208

Warning: include_once(ewmysql15.php): failed to open stream: No such file or directory in C:\xampp\htdocs\alamana\home.php on line 5
Warning: include_once(): Failed opening 'ewmysql15.php' for inclusion (include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\alamana\home.php on line 5

Fatal error: Uncaught Error: Class 'HTMLPurifier_Config' not found in C:\xampp\htdocs\alamana\phpfn15.php:10622 Stack trace: #0
C:\xampp\htdocs\alamana\home.php(6): include_once() #1 {main} thrown in C:\xampp\htdocs\alamana\phpfn15.php on line 10622

saleh

Posts: 313
Joined: Mon Dec 09, 2013 11:21 pm

Top

Display posts from previous: All posts Sort by Post time Ascending Go

Post a reply
6 posts • Page 1 of 1

Return to User Submitted Tips (PHPMaker)

Board index
Delete all board cookies • All times are UTC + 8 hours

Powered by phpBB® Forum Software © phpBB Group

You might also like