0

我正在使用以下代码从 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,但这不起作用?有人能帮助我吗?

4

2 回答 2

0

您需要设置CURLOPT_RETURNTRANSFERtrue. 如果不这样做,curl_exec将回显到屏幕而不是返回字符串。

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
于 2013-07-15T21:28:16.380 回答
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";
}
于 2013-07-16T09:41:52.410 回答