Thread: [TUT] Adding simple 'Players Online' to your website!

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 [TUT] Adding simple 'Players Online' to your website! 
    Registered Member thoompie's Avatar
    Join Date
    Feb 2007
    Age
    30
    Posts
    115
    Thanks given
    0
    Thanks received
    0
    Rep Power
    34
    Description: Making your site say how many people are playing on your server.

    Difficulty: 1/10

    Assumed Knowledge: Your SQL server info. Basic Database knowledge.

    Tested Server: Any SQL based server

    Files/Classes Modified: online.php


    You start off with remembering yourself of your SQL server Host, Username(probably 'root') and Password.
    Also you should know what field in your database tells if a player is logged on.
    On a Dodian/Devias/Devolution (SQL) server it would be field 'online' in table 'uber3_players'.
    If you have any other source with SQL, look for something like loggedon or online or anything like that.

    now Take a look at this code:
    Code:
    <?php
    $connection = mysql_connect('HOST','USER','PASSWORD');
    mysql_select_db('DATABASE', $connection);
    		$query = mysql_query('SELECT * FROM uber3_players WHERE online > 0');
    		$rows = mysql_num_rows($query);
    		if($rows == 0){
    			$playersOnline = "0 players online";
    		} elseif($rows == 1){
    			$playersOnline = "1 player online";
    		} elseif($rows > 1){
    			$playersOnline = $rows." players online";
    		} else {
    			$playersOnline = "Error occured";
    		}
    ?>
    Create a new PHP file named 'online.php' with the code above in it.
    change the following values:

    HOST = your server host.
    USER = SQL server username (probably root)
    PASS = SQL server password
    DATABASE = The database you used for your Server.
    ------------------------------------------------------

    Now as you can see i used a Dodian server for example.
    I bolded out the uber3_players and online because that part shows what to change if you have another database.
    in my case what it does is:
    SELECT * (select everything)
    FROM uber3_players (from table uber3_players in the database we specified before)
    WHERE online > 0 (where online is bigger then 0. My server sets that value to 1 if a player is logged in 1 minute, but this script also works if your server doesnt set the minutes, but just sets online (1) of offline (0) .)
    So now it has selected all players wich have their online field set to 1.
    The php script counts the rows, and knows how many players are logged in on your server.
    It attaches it to a string named "$playersOnline".
    Next thing is including and echoing the string out.
    -------------------------------------------------------

    Now to make your website show how many players are logged in you need a little piece of PHP script:

    Code:
    <?php
    include ("online.php");
    echo "$playersOnline"; ?>
    *Please notice*
    If the PHP file 'online.php' isn't in the same directory as the script in which you are going to include this script, you need to change the URL to your location of 'online.php'

    Upload all the files to your webserver, and this should work like a charm.
    If you have any question please post

    Thats all.

    Thanks very much for reading my tutorial.
    I hope it helped.
     

  2. #2  
    Si:P
    Guest
    Thank you people would love stuff like this.
     

  3. #3  
    Registered Member
    Unique's Avatar
    Join Date
    May 2008
    Posts
    457
    Thanks given
    0
    Thanks received
    1
    Rep Power
    164
    lol, the database? the server sided sql?
     

  4. #4  
    Registered Member thoompie's Avatar
    Join Date
    Feb 2007
    Age
    30
    Posts
    115
    Thanks given
    0
    Thanks received
    0
    Rep Power
    34
    Yes, Most SQL based RS servers update the online field when a player logs in.
    counting all of these fields will tell how many players are logged in.
     

  5. #5  
    cakeordeath2
    Guest
    Cool! I needed this for my new server im doing. Thanks I Repped++ You.
     

  6. #6  
    Registered Member thoompie's Avatar
    Join Date
    Feb 2007
    Age
    30
    Posts
    115
    Thanks given
    0
    Thanks received
    0
    Rep Power
    34
    Thx for replies Im working on a TUT for server restarting via Website.
    Ill release soon.
     

  7. #7  
    playermanny
    Guest
    thanks, i was looking for something simple like this
     

  8. #8  
    Registered Member
    Join Date
    Nov 2006
    Posts
    699
    Thanks given
    1
    Thanks received
    32
    Rep Power
    524
    A good add-on to this would be my version of it but in an image format. You'd probably have to work the database around, but you can find it [Only registered and activated users can see links. ].

    If you want to take this a step further, you could work with the idle logout packet on the serverside; if the user goes idle for long enough, the client sends a packet to the server saying "Hey, this guy hasn't clicked or hit a key in x seconds!". With the server, you could send the MySQL database a status update, saying that the user is idle and display, not only how many users are online, but how many users are idle. Although, this might not be a good idea because you might have 75% of your players idle, and it could really prove if your server is good or sh!t.

    ~Z
     

  9. #9  
    playermanny
    Guest
    Ill try that out also. Thanks.
     

  10. #10  
    Registered Member thoompie's Avatar
    Join Date
    Feb 2007
    Age
    30
    Posts
    115
    Thanks given
    0
    Thanks received
    0
    Rep Power
    34
    Quote Originally Posted by Zachera View Post
    A good add-on to this would be my version of it but in an image format. You'd probably have to work the database around, but you can find it [Only registered and activated users can see links. ].

    If you want to take this a step further, you could work with the idle logout packet on the serverside; if the user goes idle for long enough, the client sends a packet to the server saying "Hey, this guy hasn't clicked or hit a key in x seconds!". With the server, you could send the MySQL database a status update, saying that the user is idle and display, not only how many users are online, but how many users are idle. Although, this might not be a good idea because you might have 75% of your players idle, and it could really prove if your server is good or sh!t.

    ~Z
    Thx for feedback and suggestions mate
    I'll give it a try!
    If i succeed i'll release it to rune-server.
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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