你好我试图通过php函数检查用户是否是高级版。我使用以下代码,但结果是“Notch无效”
由于$ auth只是一个空字符串,出于某种原因,如果你转到浏览器中的url,它将显示“true”或“false”,但是当你使用file_get_contents时,没有显示字符串。< / p>
感谢您的帮助!
<?php
$input = 'Notch';
function checkPlayer($player) {
$mcURL = 'http://www.minecraft.net/haspaid.jsp?user=';
$auth = file_get_contents($mcURL . $player);
if (trim($auth) == "true") {
echo $player. ' is valid';
} else {
echo $player. ' is not valid';
}
}
checkPlayer($input);
?>
答案 0 :(得分:0)
好像它是一个HTTPs网址,为此使用 cURL
<?php
$input = 'Notch';
function checkPlayer($player) {
$mcURL = 'https://www.minecraft.net/haspaid.jsp?user=';
$mcURL = $mcURL.$player;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $mcURL);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //Add this
$auth = curl_exec($curl);
if (trim($auth) == "true") {
echo $player. ' is valid';
} else {
echo $player. ' is not valid';
}
}
checkPlayer($input);
答案 1 :(得分:0)
http URL执行301重定向到https。因此,请直接在代码中使用https网址,它应该有效:
$mcURL = 'https://www.minecraft.net/haspaid.jsp?user=';