Installation - GameServersHub/Steam-Servers-PHP-Website-Stats GitHub Wiki

Welcome to the installation wiki page on this page you'll learn how to efficiently install and set up the PHP script to work with your existing websites.


WordPress Installation


In this guide, you'll learn how to install PHP on your existing webpage using WordPress software.

Step 1. Head over to "Shortcodes Ultimate" and download the WordPress plugin to install on your website.
Step 1 Tutorial

Step 2. On your admin panel for WordPress head over to "Appearances->Theme Editor" and select the "Functions.PHP" on the right side of the webpage.
Step 2 Tutorial
Step 2 Tutorial Extra

Step 3. Copy this code below and paste it directly into a section on "Functions.PHP".

// The first 'x' text is the actual webpage shortcode. The second 'y' text is for the callback function underneath.

 add_shortcode( 'edit-me-stats' , 'edit_me_stats_shortcode_callback');

// You enter your PHP code into this section under the actual callback 'y' name.

 function edit_me_stats_shortcode_callback(){
Enter_Your_PHP_Script_HERE
 }

Step 4. Replace the "edit-me" on the three sections of PHP code above with the name you want to use. Make sure you replace all three sections with the same naming format.

Example:

// The first 'x' text is the actual webpage shortcode. The second 'y' text is for the callback function underneath.

 add_shortcode( 'game-stats' , 'game_stats_shortcode_callback');

// You enter your PHP code into this section under the actual callback 'y' name.

 function game_stats_shortcode_callback(){
Enter_Your_PHP_Script_HERE
 }

Step 5. Edit the "Enter_Your_PHP_Script_HERE" and paste in the PHP script you want to use here.
Please note; When you paste your PHP script in this section you need to remove the "< ? PHP and ? >" elements from the script since WordPress already uses PHP it won't let you save the changes unless you remove those completely from the script.

// The first 'x' text is the actual webpage shortcode. The second 'y' text is for the callback function underneath.

 add_shortcode( 'rust-stats' , 'rust_stats_shortcode_callback');

// You enter your PHP code into this section under the actual callback 'y' name.

 function rust_stats_shortcode_callback(){
        /*
        Hello everyone! Welcome to the "PHP" section of this website configuration file.
        This section is designed to give you complete control over displaying live data on your
        server community websites. One of the most significant requested features in server communities is
        being able to communicate in real-time stats directly on your websites; by doing this, you dramatically
        increase the website traffic you get, and it provides an incentive for players to use your website
        when you offer custom features such as this addon! This "PHP" script was created by https://gameservershub.com/forums/ (CEO: MrOwlSky)
        
        Style version: Style02
        Open Source Link: https://github.com/GameServersHub
        */
        $url = json_decode(file_get_contents("https://api.battlemetrics.com/servers/12261578")); // Replace "ServerKey" with your own dedicated server key from Battlemetrics.
        $serverType = $url->data->type; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverId = $url->data->id; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverName = $url->data->attributes->name; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverAddress = $url->data->attributes->address; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverIp = $url->data->attributes->ip; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverGamePort = $url->data->attributes->port; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverOnlinePlayers = $url->data->attributes->players; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverMaxPlayers = $url->data->attributes->maxPlayers; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRanking = $url->data->attributes->rank; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverLocation = $url->data->attributes->location; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverStatus = $url->data->attributes->status; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverOfficial = $url->data->attributes->details->official; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustType = $url->data->attributes->details->rust_type; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverMap = $url->data->attributes->details->map; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverEnvironment = $url->data->attributes->details->environment; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustBuild = $url->data->attributes->details->rust_build; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustEntCntI = $url->data->attributes->details->rust_ent_cnt_i; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustFps = $url->data->attributes->details->rust_fps; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustAverageFps = $url->data->attributes->details->rust_fps_avg; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustGcCl = $url->data->attributes->details->rust_gc_cl; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustGcMb = $url->data->attributes->details->rust_gc_mb; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustHash = $url->data->attributes->details->rust_hash; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustHeaderImage = $url->data->attributes->details->rust_headerimage; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustMemPv = $url->data->attributes->details->rust_mem_pv; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustMemWs = $url->data->attributes->details->rust_mem_ws; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverPve = $url->data->attributes->details->pve; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustUptime = $url->data->attributes->details->rust_uptime; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustUrl = $url->data->attributes->details->rust_url; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustWorldSeed = $url->data->attributes->details->rust_world_seed; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustWorldSize = $url->data->attributes->details->rust_world_size; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustSeed = $url->data->attributes->details->rust_maps->seed; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustSize = $url->data->attributes->details->rust_maps->size; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverUrl = $url->data->attributes->details->rust_maps->url; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverThumbnailUrl = $url->data->attributes->details->rust_maps->thumbnailUrl; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverMonuments = $url->data->attributes->details->rust_maps->monuments; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverBarren = $url->data->attributes->details->rust_maps->barren; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $severRustDescription = $url->data->attributes->details->rust_description; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustModded = $url->data->attributes->details->rust_modded; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustQueuedPlayers = $url->data->attributes->details->rust_queued_players; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustLastWipe = $url->data->attributes->details->rust_last_wipe; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustLastWipeEnt = $url->data->attributes->details->rust_last_wipe_ent; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverOwnerSteamId = $url->data->attributes->details->serverSteamId; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustPrivate = $url->data->attributes->private; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustCreatedAt = $url->data->attributes->createdAt; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverRustUpdatedAt = $url->data->attributes->updatedAt; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverQueryPort = $url->data->attributes->portQuery; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverCountry = $url->data->attributes->country; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        $serverQueryStatus = $url->data->attributes->queryStatus; // This will grab the 'XXXXXX' section from the decoded JSON and it will display it below inside the echo.
        
        // Servers online/offline status text placeholders.
        $statusString01 = $serverStatus;
        $patterns01 = array();
        $patterns01[1] = '/online/';
        $patterns01[0] = '/offline/';
        $replacements01 = array();
        $replacements01[1] = '<small class="bg-gradient bg-success border border-success rounded shadow text-center">Server is online</small>';
        $replacements01[0] = '<small class="bg-gradient bg-danger border border-danger rounded shadow text-center">Server is offline</small>';
        $replaceStatus = preg_replace($patterns01, $replacements01, $statusString01);
	 
	echo "Server Type: $serverType<br>";
        echo "Server ID: $serverId<br>";
        echo "Server Name: $serverName<br>";
 }

Step 6. Save the changes and head over to edit a web page.
Step 7. Add the "Shortcodes Ultimate" widget to your webpage. Step 7 Tutorial Step 7 Tutorial Extra

Frequently Asked Questions (F.A.Q)

Question: It won't let me save the PHP script on the theme editor page. It's giving me a syntax error, please help!
Answer: This is because you can't have the < ? PHP and ?> tags at the bottom and top of the PHP script you paste in. Removing those tags should resolve the syntax error completely.
PHP TAG


Question: How do I only add certain elements instead of displaying all of the elements?
Answer: At the very bottom of the PHP script that is posted above, see where it says "echo server name: $Text". You would replace that with whatever you want to be displayed for that shortcode tag. So if you want online players displayed you would remove all the other "echos" and only add the one you want adding for that shortcode. You can create multiple different shortcode options each using their own data. You have a full list of data that can be used inside the PHP script that you can select from.

	echo "Server Type: $serverType<br>"; // This displays the server type (You can change this to any PHP variable listed inside your PHP script.)
        echo "Server ID: $serverId<br>"; // This displays the server ID number (You can change this to any PHP variable listed inside your PHP script.)
        echo "Server Name: $serverName<br>"; // This displays the server display name (You can change this to any PHP variable listed inside your PHP script.)
⚠️ **GitHub.com Fallback** ⚠️