Thread: Players Online via Website

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Players Online via Website 
    Registered Member
    Join Date
    Jan 2015
    Age
    28
    Posts
    210
    Thanks given
    2
    Thanks received
    53
    Rep Power
    2
    Hey guys, I'm not the best web dev, but I'm trying at least. Anyways, I have an html file for my landing page, and on it I want to send the contents from a text file which is changed from "register.php" from this R-S thread: https://www.rune-server.ee/runescape...ter-667-a.html

    Register.php:
    Code:
    <?php
    $connection = $_SERVER['REMOTE_ADDR'];
    $allowed    = '127.0.0.1';
    if ($connection == $allowed) {
        $players = $_GET['amount'];
        $myFile  = "players.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $players);
        fclose($fh);
    } else {
        echo ('Nice try ;)');
    }
    ?>
    But I'm having problems reading the text file via HTML, I've googled how to do it with no real answer to my question. Any help would be appreciated.
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Dec 2016
    Posts
    21
    Thanks given
    1
    Thanks received
    2
    Rep Power
    11
    From what I understand, you are able to successfully save the current players online to a text file.

    You have trouble displaying the player count on your html page.

    Here is what you need to put in to your html file (be sure to change the file format to .php):

    Code:
    <?php
    
    	# Opens file
    	$players_file = fopen("players.txt", "r") or die("Unable to open file!");
    
    	# Reads file
    	$amount_of_players_online = fread($players_file,filesize("players.txt"));
    
    	# Closes file
    	fclose($players_file);
    
    ?>
    
    <!-- HTML Part :: Displays amount of players online -->
    
    <p>Players online: <?php echo $amount_of_players_online; ?></p>
    You probably already know, but just incase. If the players.txt file is not stored in the same directory where this code is executed, then you need to update the path at the "fopen" and "fread" lines within this code.

    I hope this helps!
    Reply With Quote  
     

  3. #3  
    Registered Member
    Project's Avatar
    Join Date
    Dec 2010
    Posts
    2,669
    Thanks given
    1,043
    Thanks received
    820
    Rep Power
    1101
    Reply With Quote  
     

  4. #4  
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    Quote Originally Posted by JordonAchilles View Post
    Hey guys, I'm not the best web dev, but I'm trying at least. Anyways, I have an html file for my landing page, and on it I want to send the contents from a text file which is changed from "register.php" from this R-S thread: https://www.rune-server.ee/runescape...ter-667-a.html

    Register.php:
    Code:
    <?php
    $connection = $_SERVER['REMOTE_ADDR'];
    $allowed    = '127.0.0.1';
    if ($connection == $allowed) {
        $players = $_GET['amount'];
        $myFile  = "players.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $players);
        fclose($fh);
    } else {
        echo ('Nice try ;)');
    }
    ?>
    But I'm having problems reading the text file via HTML, I've googled how to do it with no real answer to my question. Any help would be appreciated.
    Do something like this

    Code:
     <?php include("/online/players.txt"); ?>
    Just change your index or whatever from .html to .php if it's currently html
    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member
    Velocity's Avatar
    Join Date
    Jan 2009
    Age
    28
    Posts
    2,028
    Thanks given
    1,013
    Thanks received
    2,376
    Rep Power
    4112
    Quote Originally Posted by BoomScape View Post
    Do something like this

    Code:
     <?php include("/online/players.txt"); ?>
    Just change your index or whatever from .html to .php if it's currently html
    lmfao
    xxxxxxx
    Reply With Quote  
     


  6. #6  
    Banned
    Join Date
    Jan 2017
    Posts
    23
    Thanks given
    12
    Thanks received
    5
    Rep Power
    0
    update.php
    Code:
    <?php 
    
      $auth = "YOUR_AUTH_HERE";
      if ($_GET['auth'] == $auth) {
         file_put_contents("players.txt", $_GET['players']); 
         exit;
      }
    
      echo "403 Forbidden Access";
    
    ?>
    count.php
    Code:
    <?php 
    
      function getPlayersOnline() {
         return file_get_contents("players.txt");
      }
    
    ?>
    to use in your landing page use
    Code:
    <?php
      require_once 'count.php';
      echo getPlayersOnline();
    ?>
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Nov 2013
    Posts
    20
    Thanks given
    7
    Thanks received
    3
    Rep Power
    13
    Better save in database, but remember to protect GET
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Nov 2014
    Posts
    611
    Thanks given
    180
    Thanks received
    156
    Rep Power
    0
    Code:
    <?php
    
    	$config = array(
    
    		"auth" => 'Your auth key',
    		"link_to_file" => '',
    		"file_name" => 'players'
    
    	);
    
    	function updateCount($config) {
    		
    		if ($_GET['auth'] == $config['auth']) {
    
    			file_put_contents($config['link_to_file'] . $config['file_name'] . ".txt", $_GET['players']);
    			exit;
    
    		} else {
    
    			echo 'Your auth key was incorrect; Your count has not been updated.';
    
    		}
    
    	}
    
    	function getPlayers($config) {
    
    		if (file_exists($config['link_to_file'] . $config['file_name'] . ".txt")) {
    
    			return file_get_contents($config['link_to_file'] . $config['file_name'] . ".txt");
    
    		} else {
    
    			echo $config['file_name'] . '.txt could not be found at the given location.';
    
    		}
    
    	}
    Include that file anywhere, and you can use these functions:

    Code:
    #Update the count
    updateCount($config);
    
    #Get the player count
    getPlayers($config);
    Make sure you echo the last function.
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    May 2016
    Age
    26
    Posts
    281
    Thanks given
    162
    Thanks received
    64
    Rep Power
    96
    lol
    Send the data from the server to PHP via POST method, clean the data received from the server in PHP, ensure on the site that the only allowed IP to modify the playercount in a text file is the IP address of the server, if you know your shit with a VPS it'd probably be hosted on the same machine so it'd be localhost. Update the player count on login/logout of a player, display it nicely on the page, most decide under the logo is better.
    If you're handling MySQL connections out of PHP with GET or POST and not cleaning input (removing invalid symbols etc) then you're putting your databases at risk of SQL injection.
    Reply With Quote  
     

  10. #10  
    Banned

    Join Date
    Nov 2014
    Posts
    611
    Thanks given
    180
    Thanks received
    156
    Rep Power
    0
    Quote Originally Posted by Brandito View Post
    lol
    Send the data from the server to PHP via POST method, clean the data received from the server in PHP, ensure on the site that the only allowed IP to modify the playercount in a text file is the IP address of the server, if you know your shit with a VPS it'd probably be hosted on the same machine so it'd be localhost. Update the player count on login/logout of a player, display it nicely on the page, most decide under the logo is better.
    If you're handling MySQL connections out of PHP with GET or POST and not cleaning input (removing invalid symbols etc) then you're putting your databases at risk of SQL injection.
    Or you just you know, prepare your statements?
    And how exactly will changing a GET damage his website?
    Reply With Quote  
     

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

Similar Threads

  1. Players Online Via Website (No MYSQL)
    By Uavix in forum Tutorials
    Replies: 33
    Last Post: 02-07-2014, 01:38 AM
  2. Players online via website 667/***
    By jshdyfhgyuhdg in forum Help
    Replies: 0
    Last Post: 07-09-2012, 02:09 PM
  3. Show players online via Website
    By Tox Ow in forum Help
    Replies: 25
    Last Post: 11-06-2010, 01:27 PM
  4. Players Online Via Website
    By i say smd k in forum Requests
    Replies: 0
    Last Post: 09-24-2010, 06:06 AM
  5. Show players online via Website
    By Tox Ow in forum Help
    Replies: 2
    Last Post: 07-09-2010, 04:34 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •