• home
  • forum
  • my
  • kt
  • download
  • User online

    Author: 2007-08-24 18:58:20 From:

    Overview
    In this tutorial create 1 file
    1. user_online.php

    Step
    1. Create table "user_online" in mysql in database "test".
    2. Create file user_online.php.

    Create table "user_online"


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




    Create file - user_online.php

    ############### Code

    <?
    session_start();
    $session=session_id();
    $time=time();
    $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'";
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    if($count=="0"){
    $sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')";
    $result1=mysql_query($sql1);
    }
    else {
    "$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'";
    $result2=mysql_query($sql2);
    }

    $sql3="SELECT * FROM $tbl_name";
    $result3=mysql_query($sql3);

    $count_user_online=mysql_num_rows($result3);

    echo "User online : $count_user_online ";

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

    mysql_close();

    // Open multiple browser page for result
    ?>

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (6)
      Site Navigation (7)
      User Authentication (10)
      WAP and WML (7)
      Web Fetching (0)
      Web Traffic Analysis (11)
      XML and PHP (0)

    New

    Hot