我正在使用此脚本来解析包含JSON结构的URL。在localhost(XAMPP)上正常工作,但在服务器端不起作用。有人对此有一些建议吗?我找不到任何解决方案......
编辑:问题是我的网站运行脚本的主机。它只允许在端口80和443上进行通信。有解决方案吗?
<?php
function session_type($type) {
switch ($type) {
case 0:
return "Booking";
break;
case 1:
return "Pratica";
break;
case 2:
return "Qualifica";
break;
case 3:
return "Gara";
break;
default:
return "Error";
break;
}
}
$server = "http://95.141.37.33:8098/INFO";
$ch = curl_init($server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output = curl_exec($ch);
curl_close($ch);
$sjson = json_decode($output, true);
echo 'Current Track: ' . $sjson['track'] . '<br />';
echo 'Name: '. $sjson['name'] . '<br />';
echo 'Utenti Online: '. $sjson['clients'] . '<br />';
foreach ($sjson['cars'] as $key=>$value)
{
echo "Auto:". $value ."<br />";
};
echo 'Port: '. $sjson['port'] . '<br />';
echo 'Sessione: ' . session_type($sjson['session']) . '<br />';
echo 'Timeleft: '. $sjson['timeleft'] . '<br />';
$users = "http://95.141.37.33:8098/JSON|";
$ch = curl_init($users);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output_user = curl_exec($ch);
curl_close($ch);
$ujson = json_decode($output_user, true);
echo 'Racers: <br />';
foreach ($ujson as $key => $jsons) {
foreach ($jsons as $key => $value) {
echo $value['DriverName'] . '<br />';
}
}
?>
提前致谢