簡體   English   中英

FiveM 服務器網站的 PHP 問題

[英]Problems with PHP for a website for a FiveM server

我的網頁有 PHP 問題。 我聲明我正在為 FiveM 服務器開發網站。

在此頁面中,我必須輸入玩家數量和 FiveM 服務器可以托管的最大玩家數量。

這是我寫的:

<?php
    $file = file_get_contents('http://fivem.lrfreeroamitalia.it:30120/dynamic.json');

    $decode = json_decode($file, true);
    $clients = isset($decode['clients']);
    $svmaxclients = isset($decode['sv_maxclients']);

    echo $decode['clients'] . '/' . $decode['sv_maxclients'];
            
?>

這段代碼的問題是它給了我這個錯誤PHP:

Warning: file_get_contents(http://fivem.lrfreeroamitalia.it:30120/dynamic.json): failed to open stream: Connection timed out in /web/htdocs/www.lrfreeroamitalia.it/home/index.php on line 49

遠程服務器的 30120 端口是開放的。

PS 我使用 Aruba.it 作為提供程序

您使用 cURL 來獲取內容並顯示它們。

更多關於 cURL 的文檔: https ://www.php.net/manual/en/curl.examples.php

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://fivem.lrfreeroamitalia.it:30120/dynamic.json',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);

$obj = json_decode($response);
echo $obj->clients . '/' . $obj->sv_maxclients;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM