Monday, November 11, 2013

Your own php online counter for website

This is the script for online counter .It can be used in your website to display online visitors in your site.

(use with your own css to have a better look)

*How to make ?

Step 1 ==>In your php site make a database.
Note the username,password and the database name of the created database.

Step 2 ==> Now create two files sql.sql and user_online.php in your site using ftp.

Step 3 ==>Copy and paste below content to user_online.php


Dedicated to Our New Member Arun Raj and Okechukwu Friday

//SET TIME 10 Minute

$host="paste mysql server name here"; //My sql Host name obtained from the host
$username="paste username of database"; // Mysql username
$password="paste password of database"; // Mysql password
$db_name="paste name of database"; // Database name
$tbl_name="user_online"; // Table name

// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE session='$session'";


$sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')";
else {
"$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'";

$sql3="SELECT * FROM $tbl_name";


echo "Online ($count_user_online) ";

// if over 10 minute, delete session
$sql4="DELETE FROM $tbl_name WHERE time<$time_check";


// Open multiple browser page for result

Step4==> Copy and paste below code to sql.sql file

CREATE TABLE `user_online` (
`session` char(100) NOT NULL default '',
`time` int(11) NOT NULL default '0'
Step5==> Now save and again open the sql.sql file.
There will be an option in the ftp site like "create sql setup wizard". Click it
A form will appear . Fill it as given below

Server:paste mysql server name
User: paste mysql username
Password:paste mysql password
Database:paste mysql database name
and click submit.

Now type the location of  install.php  (like in your web browser and go to the url.

== Now it is ready to use ====
if you do not see "create sql setup wizard" in your ftp client just enter the phpmyadmin of your mysql database and paste the contents of sql.sql file there and run that script.

*How to use ?

In your php site use "include" function
to display this counter.

Eg: echo'<div class="smart_coders">';include 'user_online.php';

Enjoy this counter.

Demo Here: