Guests online?

Discussion in 'PHP' started by red-x, Nov 17, 2008.

  1. #1
    How can I know how many guests are browsing my website? Any help will be appreciated. Thank you in advance :)
     
    red-x, Nov 17, 2008 IP
  2. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Try many of the available web counters which can even track no of pages visited and no of users online.

    Ex -

    1) histats.com
    2) whos.amung.us

    Try these :)
     
    harrisunderwork, Nov 18, 2008 IP
  3. osocash

    osocash Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    whos are the best I think but they are kinda slow sometimes.
     
    osocash, Nov 18, 2008 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    are you referring to the visitor counters? or every page current visitors?
     
    bartolay13, Nov 18, 2008 IP
  5. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #5
    Whipped something up real quick... This lets you display number of guests online within the last 5 minutes.
    <?php
    	@mysql_connect('', '', '') && @mysql_select_db('') || die(mysql_error());
    	if (mysql_num_rows(mysql_query("SELECT * FROM `online` WHERE `online_ip` = '$_SERVER[REMOTE_ADDR]' AND `online_time` > UNIX_TIMESTAMP(NOW()) - 300"))) {
    		mysql_query("UPDATE `online` SET `online_time` = UNIX_TIMESTAMP(NOW()) WHERE `online_ip` = '$_SERVER[REMOTE_ADDR]'";
    	} else {
    		mysql_query("INSERT INTO `online` (`online_ip`, `online_time`) VALUES ('$_SERVER[REMOTE_ADDR]', UNIX_TIMESTAMP(NOW()))");
    	}
    	$guests_online = mysql_num_rows(mysql_query("SELECT * FROM `online` WHERE `online_time` > UNIX_TIMESTAMP(NOW()) - 300"));
    ?>
    PHP:
    Include that in any page and use $guests_online to display them on any page.

    Execute this in MySQL for the table, and don't forge to fill in your MySQL info.
     CREATE TABLE `online` (
    `online_ip` VARCHAR( 16 ) NOT NULL ,
    `online_time` INT( 10 ) NOT NULL
    ) ENGINE = MYISAM
    Code (markup):
     
    Equaite, Nov 19, 2008 IP
  6. red-x

    red-x Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Wow thanks guys, you guys are awesome :)
     
    red-x, Nov 19, 2008 IP
  7. AdultProfiles

    AdultProfiles Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The best solution is to use AJAX and PHP to do that.
    Each time someone open ur index page add 1 into a flat file or db and when close subtract 1 (this can be made at window.close event)

    Cheers
     
    AdultProfiles, Nov 20, 2008 IP
  8. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #8
    Reputation will be highly appreciated :)
     
    harrisunderwork, Nov 20, 2008 IP
  9. Aquarezz

    Aquarezz Notable Member

    Messages:
    3,009
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    225
    #9
    Don't ask for reputation here at DP :D

    If people like it than they will rep you ;)

    Also.. thanks for the script, I'm using it on my proxies now :)


    Greetz
     
    Aquarezz, Nov 20, 2008 IP
  10. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #10
    Its because some really dont know about reps here . A line is worth thousand meanings :)
     
    harrisunderwork, Nov 20, 2008 IP
  11. eric90

    eric90 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    you could also use register globals, although not very secure, it should do fine for tracking guests.
     
    eric90, Nov 21, 2008 IP
  12. Equaite

    Equaite Active Member

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    Digital Goods:
    1
    #12
    No problem. I coded it up in a few minutes and didn't test it, I'm glad it works though :D
     
    Equaite, Nov 21, 2008 IP
  13. lip9000

    lip9000 Peon

    Messages:
    325
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Also if you wanted you could modify Equaite's script and add another database field for the current page, then insert global variables on each page with a different name, then insert that value into the database depending on which page the user is on.

    You could then show how many users are on certain pages like home, about us, chat room etc.

    
    
    $_GLOBAL['pagename'] = "chatroom";
    
    if($_GLOBAL['pagename'] == "chatroom"){
    
    //INSERT chatroom into the page field
    
    }elseif($_GLOBAL['pagename'] == "homepage"){
    
    //INSERT homepage into the page field
    
    }
    
    PHP:
    etc.etc.
     
    lip9000, Nov 21, 2008 IP