Oh great, so I would just simply make the rows, and then paste the code into my file and change all thats needed an its done? Thats great ;D Thanks alot! So when I would click a link it would come to a table showing whos online? Or...?
How Many Users Online
#18
Posted 10 December 2015 - 10:01 AM
Hi
I am using this script and seems to be working as checked the database and is data within the table
on the front end, I have created the php file called usersonline.php and have a backend admin panel and created a page called users-online.php to show the number of users online but the admin side don't seem to be detecting users online
below is the code I have for the front end php file usersonline.php
Below is the coding I have from the in the php file users-online.php which is in the admin folder
Hope someone can help me where I am going wrong, I am not getting any errors in the admin side php file
Thank you in advance
Ian
I am using this script and seems to be working as checked the database and is data within the table
on the front end, I have created the php file called usersonline.php and have a backend admin panel and created a page called users-online.php to show the number of users online but the admin side don't seem to be detecting users online
below is the code I have for the front end php file usersonline.php
<?php //Put your basic server info here $server = "localhost"; //normally localhost $db_user = ""; //your MySQL database username $db_pass = ""; //your MySQL database password $database = ""; $timeoutseconds = 300; //this is where PHP gets the time $timestamp = time(); $timeout = $timestamp - $timeoutseconds; //connect to database //$server = localhost probably //$db_user = your MySQL database username //$db_pass = //your MySQL database password $mysqli = new mysqli($server, $db_user, $db_pass, $database); //insert the values $insert = "INSERT INTO useronline VALUES (?, ?, ?)"; $stmt = $mysqli->prepare( $insert ); $stmt->bind_param( 'iss', $timestamp, $_SERVER['REMOTE_ADDR'],$_SERVER['PHP_SELF'] ); if(!$stmt->execute()) { print "Useronline Insert Failed > "; } //delete values when they leave $delete = "DELETE FROM useronline WHERE timestamp < ?"; $stmt = $mysqli->prepare( $delete ); $stmt->bind_param( 'i', $timeout ); if(!$stmt->execute()) { print "Useronline Delete Failed > "; } //grab the results $result = "SELECT DISTINCT ip FROM useronline WHERE file = ?"; $stmt = $mysqli->prepare( $result ); $stmt->bind_param( 's', $_SERVER['PHP_SELF'] ); if(!$stmt->execute()) { print "Useronline Select Error > "; } //number of rows = the number of people online $user = $stmt->num_rows; //spit out the results $mysqli->close(); /*if($user == 1) { print("$user user online\n"); } else { print("$user users online\n"); }*/ ?>
Below is the coding I have from the in the php file users-online.php which is in the admin folder
<?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <html> <head> <title>Users Online</title> </head> <body> <script> var t; window.onload=resetTimer; document.onkeypress=resetTimer; function logout() { alert("You are now logged out.") location.href='logout.php' } function resetTimer() { clearTimeout(t); t=setTimeout(logout,1800000) //logs out in 30 minutes } </script> <? session_start(); if($_SESSION['user']==''){ header("Location:index.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM users WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; echo "<br>"; } } ?> <?php //Put your basic server info here $server = "localhost"; //normally localhost $db_user = ""; //your MySQL database username $db_pass = ""; //your MySQL database password $database = ""; $timeoutseconds = 300; //this is where PHP gets the time $timestamp = time(); $timeout = $timestamp - $timeoutseconds; //connect to database //$server = localhost probably //$db_user = your MySQL database username //$db_pass = //your MySQL database password $mysqli = new mysqli($server, $db_user, $db_pass, $database); //grab the results $result = "SELECT DISTINCT ip FROM useronline WHERE file = ?"; $stmt = $mysqli->prepare( $result ); $stmt->bind_param( 's', $_SERVER['PHP_SELF'] ); if(!$stmt->execute()) { print "Useronline Select Error > "; } //number of rows = the number of people online $user = $stmt->num_rows; //spit out the results $mysqli->close(); if($user == 1) { print("$user user online\n"); } else { print("$user users online\n"); } ?> </body> </html>
Hope someone can help me where I am going wrong, I am not getting any errors in the admin side php file
Thank you in advance
Ian