Berserk Posted October 1, 2023 Share Posted October 1, 2023 I'm not sure if i post this in the wrong section i have this php code which retrives the server information and display them within a website <?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/vendor/autoload.php'; // Include Composer autoloader use Knik\GRcon\GRcon; use Knik\GRcon\Protocols\GoldSourceAdapter; // Server details $serverHost = '54.36.237.158'; $serverPort = '27015'; $rconPassword = 'test'; // Replace with your actual RCON password // Retry parameters $maxRetries = 3; // Maximum number of retry attempts $retryDelay = 2; // Delay in seconds between retry attempts for ($retry = 0; $retry < $maxRetries; $retry++) { try { // Create GoldSource RCON adapter $adapter = new GoldSourceAdapter([ 'host' => $serverHost, 'port' => $serverPort, 'password' => $rconPassword, ]); // Initialize RCON connection $rcon = new GRcon($adapter); // Attempt to execute RCON command to get server info $response = $rcon->execute('status'); // Parse server response to extract information $serverInfo = []; preg_match('/hostname:\s+(.+)/', $response, $matches); if (isset($matches[1])) { $serverInfo['hostname'] = $matches[1]; } preg_match('/map\s+:\s+(.+)/', $response, $matches); if (isset($matches[1])) { // Remove the "at: 0 x, 0 y, 0 z" part $serverInfo['map'] = preg_replace('/\sat:\s[0-9]+ x,\s[0-9]+ y,\s[0-9]+ z/', '', $matches[1]); } preg_match('/players\s+:\s+(\d+)/', $response, $matches); if (isset($matches[1])) { $serverInfo['playerCount'] = intval($matches[1]); } // Display server information echo "<h2>Server Name: " . $serverInfo['hostname'] . "</h2>"; echo "<h3>Current Map: " . $serverInfo['map'] . "</h3>"; echo "<h3>Player Count: " . $serverInfo['playerCount'] . "</h3>"; break; // Connection and query were successful, exit retry loop } catch (Throwable $e) { echo "Error: " . $e->getMessage() . "<br>"; if ($retry < $maxRetries - 1) { sleep($retryDelay); // Wait before retrying } else { echo "Unable to connect after $maxRetries retries."; } } } ?> the code is working fine , however i want to include this script in a phpbb forum description something i can't figure out at all Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/ Share on other sites More sharing options...
ginerjm Posted October 1, 2023 Share Posted October 1, 2023 You "want to include this script in a phpbb forum description"? Do you actually mean you want to publish your code as part of some text somewhere else? Doesn't make much sense. Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612206 Share on other sites More sharing options...
Berserk Posted October 1, 2023 Author Share Posted October 1, 2023 46 minutes ago, ginerjm said: You "want to include this script in a phpbb forum description"? Do you actually mean you want to publish your code as part of some text somewhere else? Doesn't make much sense. that code gives this result In phpbb every forum allows you to put a description to it basically in want that in the description to be displayed the result of the code presented above Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612207 Share on other sites More sharing options...
ginerjm Posted October 1, 2023 Share Posted October 1, 2023 So you DON'T want to include the script in the text description? Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612208 Share on other sites More sharing options...
dodgeitorelse3 Posted October 1, 2023 Share Posted October 1, 2023 (edited) It looks like OP is wanting to show current server data in a forum. The image OP posted is from a game server query I think. Very similar to the game server queries I run on my site except I don't display results in a forum. Edited October 1, 2023 by dodgeitorelse3 Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612209 Share on other sites More sharing options...
Berserk Posted October 1, 2023 Author Share Posted October 1, 2023 5 hours ago, ginerjm said: So you DON'T want to include the script in the text description? ... the server details that are retrieve using the code above I want to display them into the description of a forum Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612210 Share on other sites More sharing options...
requinix Posted October 2, 2023 Share Posted October 2, 2023 There are two approaches that aren't unreasonable: 1. Make your thing render as an image, and embed the image into the description (assuming it supports HTML). Then whoever sees the description will see the image. Not great for SEO or visually-impaired users. 2. Set up a cronjob that runs a script every X minutes (whatever makes sense to you). This script calculates what it needs, then goes into the database and manipulates the forum's description text. Quote Link to comment https://forums.phpfreaks.com/topic/317336-include-a-php-code-within-a-forum-description/#findComment-1612211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.