PHP Project-4 :PHP User online tutorial

Posted: November 7, 2010 in MySql, PHP
Tags: ,

In this tutorial create 1 file
1. user_online.php

1. Create table “user_online” in mysql in database “test”.
2. Create file user_online.php.

1. Create table “user_online”

CREATE TABLE `user_online` (
`session` char(100) NOT NULL default '',
`time` int(11) NOT NULL default '0'

2. Create file – user_online.php


$time_check=$time-600; //SET TIME 10 Minute

$host="localhost";  // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // 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  "User 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
  1. Ravinder Singh says:

    Hello Sir,

    You code is very much helpfull for me,its really good,will u plz help me also to make me professional in php +mysql.

    with regards
    Ravinder Singh

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s