从file_get_contents获取数据并在“Y”时重定向

时间:2013-11-25 07:58:23

标签: php ip file-get-contents

我还是PHP新手。如果来自http://www.shroomery.org/ythan/proxycheck.php?ip=xxxxxx的数据为Y,我想重定向用户,如果是N则不执行任何操作。 我在下面有这个代码。不确定是否正确。那我接下来该怎么办?

<?PHP
// Function to get the client ip address
function get_client_ip() {
    $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP'])
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if($_SERVER['HTTP_X_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if($_SERVER['HTTP_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';

    return $ipaddress;
}


$userIP=get_client_ip();

$xml = file_get_contents("http://www.shroomery.org/ythan/proxycheck.php?ip=$userIP");


?>

谢谢。

1 个答案:

答案 0 :(得分:0)

类似的东西,

if( $xml === 'Y' )
    header('Location: http://www.something.com');

http://php.net/manual/en/function.header.php