Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1

    Default Mentor or somebody may be able to help...

    Thanks to Mentor, I now have a goo ajax reload. Anyway, I have a script which says how many users are online, and the ajax displays it and updates every 10 seconds. Anyway, I have it set to refresh every 10 seconds, and it deletes users from the database as soon as they're inactive, but I want it so it does it when they're not on the page. So say there are 3 users online: User 1 goes to the page, (it's a game, so they can't keep reloading the page), user 2 is also at the page and 3 is. So it displays 3 users online. Then 10 seconds later, it deletes from the database, so it says there is 0 users on. But they are still at the page and are actually on.

    I want it so it says they're on when they're at the page, and for it to only delete them from the list/database when they actually leave the page. Heres the code:

    PHP Code:
    <?
    /**
     *
     * TG WHO'S ONLINE
     * Copyright 2005 - 2006 (c) TOXIC GOBLIN
     * http://www.toxicgoblin.com
     * 
     */
     
    //Optional Database Connection Information
    //**Uncomment the following 2 lines and edit the values if you do not already have an active database connection**
    //
    //$db = mysql_connect("localhost", "username", "password") or die("Could not connect");
    //mysql_select_db("database_name");

    include 'config.php';
    //Fetch Time
    $timestamp time();
    $timeout $timestamp 10;

    //Insert User
    $insert mysql_query("INSERT INTO TG_whos_online (timestamp, ip, file) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')") or die("Error in who's online insert query!");
    //Delete Users
    $delete mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
    //Fetch Users Online
    $result mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
    $users mysql_num_rows($result);

    //Show Who's Online
    if($users == 1) {
    print(
    "There is $users user online!\n");
    } else {
    print(
    "There are $users users online!\n");
    }
    ?>
    As you can see it deleted them every 10 seconds, and updates the page so it says they're not there unless they refresh - then they're there again for 10 seconds. But I want it so they're on when they're at the page, and no on when they're not on it, but I want it to update instantly.

    I hope you understand what I'm on about, anybody with good coding knowledge or in the know of a code, please help.

    Thanks!

    Edited by L&#181;ke (Forum Moderator): Thread Moved from Website Designing. Please post in the correct section next time, Thanks .
    Last edited by Lµke; 26-04-2007 at 05:52 PM.
    I'm not going to be using this account anymore, after today!

  2. #2
    Oni Guest

    Default

    Ill m s n him

  3. #3

    Default

    Ok thanks Ozzie.
    I'm not going to be using this account anymore, after today!

  4. #4

    Default

    *Can't edit*

    $timeout = $timestamp - 10; is the part, I need it to be "when they close window" if you get what I mean. I want no timeout, only when they press X to the window (theres also a text link that says CLOSE).
    I'm not going to be using this account anymore, after today!

  5. #5
    Join Date
    Dec 2006
    Location
    Northamptonshire, England.
    Posts
    1,303
    Tokens
    0

    Latest Awards:

    Default

    <?
    /**
    *
    * TG WHO'S ONLINE
    * Copyright 2005 - 2006 (c) TOXIC GOBLIN
    * http://www.toxicgoblin.com
    *
    */

    //Optional Database Connection Information
    //**Uncomment the following 2 lines and edit the values if you do not already have an active database connection**
    //
    //$db = mysql_connect("localhost", "username", "password") or die("Could not connect");
    //mysql_select_db("database_name");

    include 'config.php';
    //Fetch Time
    $timestamp = time();
    $timeout = $timestamp - 3600;

    //Insert User
    $insert = mysql_query("INSERT INTO TG_whos_online (timestamp, ip, file) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')") or die("Error in who's online insert query!");
    //Delete Users
    $delete = mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
    //Fetch Users Online
    $result = mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
    $users = mysql_num_rows($result);

    //Show Who's Online
    if($users == 1) {
    print("There is $users user online!\n");
    } else {
    print("There are $users users online!\n");
    }
    ?>

  6. #6

    Default

    Yeah, Ryan, but if they leave it wont show it untill that amount of time. I want it so if somebody leaves, it goes down instantly, but not when somebody is on then it goes off and they're still there.
    I'm not going to be using this account anymore, after today!

  7. #7
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Well you cant really do it instantly via ajax, there will be some delay. Say if you dont mind the delay being 10 seconds, youd need the script to be accessed every 10 or maybe slightly less than 10 seconds to maintain the entery.

    The easyest way to do this would just be change the ajax script to it connects to the online script every 10 seconds (or slightly less) ?

    Also, are you sure "$timeout = $timestamp - 10;" shouldnt be "$timeout = $timestamp + 10;" ?

  8. #8

    Default

    Quote Originally Posted by 01101101entor View Post
    Well you cant really do it instantly via ajax, there will be some delay. Say if you dont mind the delay being 10 seconds, youd need the script to be accessed every 10 or maybe slightly less than 10 seconds to maintain the entery.

    The easyest way to do this would just be change the ajax script to it connects to the online script every 10 seconds (or slightly less) ?

    Also, are you sure "$timeout = $timestamp - 10;" shouldnt be "$timeout = $timestamp + 10;" ?
    Hi Mentor, I don't mind a delays, up to 1 min is fine!

    How would I do that, could you provide a code? Thanks if you can!

    It works with - 10, ill try + 10 thanks.

    OK, I did + 10 and it displays 0 users, on - 10 it says 1. and works.
    So, about this thing to connect to the script.
    Last edited by UnderGROUND; 22-04-2007 at 12:32 PM.
    I'm not going to be using this account anymore, after today!

  9. #9
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Well basicly the thing that connects to the scripts is the ajax script you requested erleyer, you just need to make it access the online script more often (aka when it uses the xmlhttp request to get the users online data)

  10. #10
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Cant you use javascript? Im sure theres a script which does like if me.close (vB i think lol) it does something, e.g.

    Javascript code:

    if(window.close) *

    run a php script here which removes them from database

    * someone make a script which does that for js.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •