我的网页有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是打开的。
我使用Aruba.it作为提供者
发布于 2022-06-16 18:07:15
您可以使用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;https://stackoverflow.com/questions/72649258
复制相似问题