【发布时间】:2017-06-04 02:26:44
【问题描述】:
我正在尝试创建一个网站,该网站从我的世界服务器创建的数据库中获取统计信息。我在将 uuid 插入 mojangs API 并作为用户名出现时遇到问题。当您第一次访问该站点时它可以工作,但是当您刷新它时我收到错误:
Warning: file_get_contents(https://sessionserver.mojang.com/session/minecraft/profile/07eb744f35b74ac083e90e0377a5a967): failed to open stream: HTTP request failed! HTTP/1.1 429 429 in C:\xampp\htdocs\index.php on line 47
Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 49
Warning: file_get_contents(https://sessionserver.mojang.com/session/minecraft/profile/f5cf9ff1b9a74176983bb8b1d0c0ee70): failed to open stream: HTTP request failed! HTTP/1.1 429 429 in C:\xampp\htdocs\index.php on line 47
Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 49
在我刷新它之后,名称从表格中消失了,它给了我这些错误。我真的需要尽快解决这个问题!
<code>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: arial;
background-color: #3be5de;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
</style>
<title>SuperBlaze27 Players-Server Stats</title>
<!--<link>-->
</head>
<body>
<div style="font-family: arial; color: #23a09b;">
<h1>SuperBlaze27 Minecraft Server Player Stats</h1>
<h3>Player joins</h3>
</div>
<?php
$servername = "localhost";
$username = "stats";
$password = "***";
$dbname = "stats3";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `stats3_joins`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<table><tr><th>Uniqe Player ID</th><th>Username</th><th>Player Head</th><th>Times Joined</th></tr>
";
while($row = $result->fetch_assoc()) {
$uuid = $row["uuid"];
$uuid = str_replace('-', '', $uuid);
$json_response = file_get_contents("https://sessionserver.mojang.com/session/minecraft/profile/" . $uuid . "");
$data = json_decode($json_response);
print "<tr><td>#" . $row["id"]. "</td><td> ". $data->name . "</td><td><img src='https://crafatar.com/avatars/" . $uuid . "?size=32'/img></td><td>" . $row["value"]. "</td></tr>";
}
} else {
echo "0 results";
}
$conn->close();
echo "</table>";
// echo "Player name:".$data->name;
?>
</body>
</html>
顺便说一句,我用 *** 替换了密码,但在真正的密码中它可以工作,所以这不是问题。提前谢谢!
【问题讨论】:
-
你能应用一致的格式吗?像 pastebin 这样的网站可以提供帮助。
-
@mateusz-sip pastebin.com/raw/KSm31q1T
-
您确定
$json_response = file_get_contents("https://sessionserver.mojang.com/session/minecraft/profile/" . $uuid . "");返回有效响应吗? -
您将其视为有效数据源而不检查其行为。
-
@mateusz-sip hmmmm 你是什么意思?我该如何解决?