我正在使用以下代码从minecraft.net检索玩家帐户状态。
//Checks MC Username For Validation
function checkPlayer($player) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init('http://www.minecraft.net/haspaid.jsp?user='.$player.'');
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
$content = curl_exec($ch);
curl_close($ch);
if (trim($output) == true) {
return true;
} else {
return false;
}
我的主机安装了Curl,我使用的是file_get_content
而不是{{1}},但这不起作用?有人能帮帮我吗?
答案 0 :(得分:0)
您需要将CURLOPT_RETURNTRANSFER
设置为true
。如果不这样做,curl_exec
将回显到屏幕而不是返回字符串。
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
答案 1 :(得分:0)
这是你的脚本,完全正常工作。
$player = 'PLAYER_NAME';
$url = 'http://www.minecraft.net/haspaid.jsp?user=' . $player;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec ($ch);
curl_close ($ch);
echo 'RESULT: '. $result;
if ($result === 'true') {
echo "STATUS OK_OR_WHATEVER";
} else {
echo "STATUS FLASE_OR_WHATEVER";
}