Results 1 to 10 of 10

how many users online, PHP how many users online, PHP

This is a discussion on how many users online, PHP how many users online, PHP within the Programming forums, part of the Web Designing & Development category; is there a way to display how many users are online in the site in PHP without utilizing mysql?...

  1. #1
    Junior Member Array
    Join Date
    Feb 2010
    Posts
    10

    Default how many users online, PHP how many users online, PHP

    is there a way to display how many users are online in the site in PHP without utilizing mysql?

  2. #2
    Junior Member Array
    Join Date
    Feb 2010
    Posts
    9

    Default Re: how many users online, PHP how many users online, PHP

    yeah, the easiest way is to use pre-made scripts or services offering that. Im using whos[dot]amung[dot]us in my blog and are very glad with that.

  3. #3
    Junior Member Array
    Join Date
    Feb 2010
    Posts
    10

    Default how many users online

    create a blank file and name it [COLOR=Red]online.txt
    [/COLOR]

    create a file[COLOR=Red] online.php [/COLOR]and add the below code to it.

    Upload to your server and give [COLOR=Blue]online.txt [/COLOR]write permissions.

    PHP Code:
    <?php

    $userip 
    $_SERVER['REMOTE_ADDR'];
    $time time();
    $usersonline 0;
    $alreadyonline 0;

    $onlinetxt fopen("online.txt","r+");
    flock($onlinetxt,2);
    while (!
    feof($onlinetxt)) { 
    $user[] = chop(fgets($onlinetxt,65536));
    }
    fseek($onlinetxt,0,SEEK_SET);
    ftruncate($onlinetxt,0);
    foreach (
    $user as $line) {
    @list(
    $savedip,$savedtime) = split("\|",$line);
    if (
    $savedip == $userip) {
      
    $savedtime $time;
      
    $alreadyonline 1;
    }
    if (
    $time $savedtime + ($session_length)) {
      
    fputs($onlinetxt,"$savedip|$savedtime\n");
      
    $usersonline $usersonline 1;
    }
    }
    if (!
    $alreadyonline) {
    fputs($onlinetxt,"$userip|$time\n");
    $usersonline $usersonline 1;
    }
    fclose ($onlinetxt);
    $num= array("0""0");
    shuffle($num);
    $q=$num[0];
    $usersonline $usersonline $q;

    if(
    $usersonline==1){
    echo 
    "<center><b><FONT color=\"#FF00FF\">1 useronline</FONT></b></center>";
    } else {
    echo 
    "<center><b><FONT color=\"#FF00FF\">".str_replace("%1",$usersonline,"%1 usersonline")."</FONT><b></center>";
    }
    ?>

  4. #4
    Junior Member Array
    Join Date
    Mar 2010
    Posts
    10

    Default Re: how many users online, PHP how many users online, PHP

    Why not just create a session on page load, and assign $_SESSION["user"] to "Guest" or another anonymous name. Then to display Who's Online just count the session array. Haven't tried this method first hand (never had a reason to show this type of data) but I don't see why it wouldn't work.

    All in all it would be about 3 lines of code.

  5. #5
    Junior Member Array
    Join Date
    Mar 2010
    Posts
    6

    Default Re: how many users online, PHP how many users online, PHP

    Hello rosahuset
    I tried your code, but when i refresh page it shows 0 useronline

  6. #6
    Junior Member Array
    Join Date
    Mar 2010
    Posts
    5

    Default Re: how many users online, PHP how many users online, PHP

    the easiest way to count online users is to create a new $_SESSION for each user and then count the number of files in your "session.save_path" directory.

  7. #7
    Senior Member Array devashishseo's Avatar
    Join Date
    Sep 2010
    Location
    Noida
    Posts
    289

    Default Re: how many users online, PHP how many users online, PHP

    Hi, rosahuset, the code is not working properly.

  8. #8
    Member Array
    Join Date
    Oct 2010
    Posts
    60

    Default Re: how many users online, PHP how many users online, PHP

    OOH i got useful information..

  9. #9
    Member Array
    Join Date
    Nov 2010
    Posts
    94

    Default Re: how many users online, PHP how many users online, PHP

    it will be very Valuable information . thnx

  10. #10
    Member Array
    Join Date
    Feb 2012
    Posts
    44

    Default Re: how many users online, PHP how many users online, PHP

    the easiest method to rely web users is to make a new $_SESSION for each individual and then rely the variety of details in your "session.save_path" catalog.



Similar Threads

  1. hi forum users
    By creamy in forum Introductions
    Replies: 10
    Last Post: 11-20-2009, 01:34 AM
  2. Google is pushing away users from IE.
    By seonavigator in forum Google
    Replies: 10
    Last Post: 09-03-2009, 03:26 AM
  3. Is there any adsense users union?
    By Madinfo in forum Google
    Replies: 1
    Last Post: 10-29-2008, 02:35 PM
  4. New Users Read This Before Posting
    By Bamzo in forum Suggestions & Feedback
    Replies: 0
    Last Post: 03-27-2008, 07:26 PM
  5. Hello to all Users of WebICY
    By markpaul in forum Introductions
    Replies: 3
    Last Post: 02-12-2008, 04:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |