WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Users online - This script lets you know how many people are there on your site at the same time.
Categories : PHP, Filesystem, Beginner Guides Click here to Update Your Picture
Shashank Prabhakara
Date : May 30th 2009
Grade : 2 of 5 (graded 4 times)
Viewed : 11436
File : 4975.zip
Images : No Images for this code example.
Search : More code by Shashank Prabhakara
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

Its just natural to brag about how many users you have on your site.

Check the file for instructions.
If you problems with "the no. users" visiting your site you can always tweak the no. a little :)


Install.txt
           +----------------------------------------+
           |             UserOnline 2.1             |
           |                                        |
           |   Documentation for the installation   |
           |            of UserOnline 2.1           |
           |                                        |
           +----------------------------------------+


In order to setup the UserOnline Script, you must do the following: 

1. unpack ZIP
2. Edit config.php3
3. Upload all files
4. Insert the UserOnline code into the pages, that the current 
number of users should be shown

+----------------------------------------+
After you've unpacked the zip, you have to edit the variables in the config.php3.

<?php

// Timeout - After this time the users will 
// be deleted (in minutes)
$timer = 100;

// Name of the file where all the data, about
// the user's activity will be saved
$filename = "$DOCUMENT_ROOT/useronline/log.txt";

?>

+----------------------------------------+
There are two possibilities to setup the UserOnline script on your homepage: 

A. HTML: <img src="your/path/to/useronline.php4" width="1" height="1">
If you chose the HTML version, the current number of users won't be shown,
but the user will be logged.

B. PHP: <?php include("your/path/to/useronline.php4"); ?>
Please consider that when you insert the PHP code, the current amount of
users online will be outputted. 
The pages that you insert this code into have to be PHP 4 compatible


+----------------------------------------+




config.php3
<?php

// Timeout - After this time the users will 
// be deleted (in minutes)
$timer = 100;

// Name of the file where all the data, about
// the user's activity will be saved
$filename = "$DOCUMENT_ROOT/useronline/log.txt";
?>



useronline.php
<?php


include ("./config.php3");

if (!
$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$ip|$time\n";
$a = fopen("$filename", "a+");
fputs($a, $string);
fclose($a);

$timeout = time()-(60*$timer);

$all = "";
$i = 0;
$datei = file($filename);
for (
$num = 0; $num < count($datei); $num++) {
   
$pieces = explode("|",$datei[$num]);

        if (
$pieces[1] > $timeout) {
           
$all .= $pieces[0];
           
$all .= ",";
        }
   
$i++;
}

$all = substr($all,0,strlen($all)-1);
$arraypieces = explode(",",$all);
$useronline = count(array_flip(array_flip($arraypieces)));

// display how many people where activ within $timeout
echo $useronline;

// Delete
$dell = "";
for (
$numm = 0; $numm < count($datei); $numm++) {
   
$tiles = explode("|",$datei[$numm]);
        if (
$tiles[1] > $timeout) {
           
$dell .= "$tiles[0]|$tiles[1]";
        }
}

if (!
$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$dell";
$a = fopen("$filename", "w+");
fputs($a, $string);
fclose($a);
?>






Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Selecting a random line from a text file
Categories : PHP, Filesystem, Arrays, Beginner Guides
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
How to overide the Max_file_size barier
Categories : PHP, PHP Configuration, Filesystem
Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
Find if a year is leap.
Categories : PHP, Date Time, Beginner Guides, Data Validation
Using PHP to Delete a directory with all sub directories and files using FTP
Categories : PHP, FTP, Directories, Filesystem
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
How to create an empty file? (touch)
Categories : Filesystem, PHP
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes