PHP Global关键字不起作用

时间:2015-05-04 16:22:08

标签: php global

我有以下文件,它包含一个名为' vote.php'其中包含一些所需的功能..

require _PATH_.'/core/includes/vote/vote.php';
$ip_address = $_SERVER['REMOTE_ADDR'];
$voting_sites[0]['name'] = 'Runelocus';
$voting_sites[0]['url'] = 'http://www.runelocus.com/top-rsps-list/vote-39865-Hydrascape%20HD%20639%20Beta%20-%20Original%20Staf/?id2='.getIPString($ip_address);
$voting_sites[0]['callback'] = true;

$voting_sites[1]['name'] = 'Top100Arena';
$voting_sites[1]['url'] = 'http://www.top100arena.com/in.asp?id=85854&incentive='.getIPString($ip_address);
$voting_sites[1]['callback'] = true;

$voting_sites[2]['name'] = 'TopG';
$voting_sites[2]['url'] = 'http://topg.org/Runescape/in-393646-'.getIPString($ip_address);
$voting_sites[2]['callback'] = true;

$voting_sites[3]['name'] = 'RSPS-List';
$voting_sites[3]['url']= 'http://www.rsps-list.com/index.php?a=in&u=Hydrascape&id='.getIPString($ip_address);
$voting_sites[3]['callback'] = true;

其中包括' vote.php'但是我无法在任何getIpString函数中访问$ char_table,即使我使用global关键字,print_r也会返回null,为什么会这样?

$char_table = array("k", "V", "R", "c", "H", "x", "i", "a", "p", "z", "W", "Y");
echo 'v1';
/*
 * Converts an Ipv4 address to an 'encrypted' version able to pass on to voting sites
 * which will be received by callbacks
 */
function getIPString($ip) {
    $ret = "";
    global $char_table;
    die(print_r($char_table, true));

    for($i = 0; $i < strlen($ip); $i++){
        $char = $ip{$i};
        if($char == '.')
            $ret .= 'E';
        else
            $ret .= $char_table[$char];
    }
    return addslashes($ret);
}
/*
 * Reverses an 'encrypted' ip string back to a normal Ipv4 address
 */
function reverseIPString($string) {
    $ret = "";
    global $char_table;
    for($i = 0; $i < strlen($string); $i++) {
        $char = $string{$i};

        if($char == 'E') {
            $ret .= '.';
        } else {
            for($x = 0; $x < sizeof($char_table); $x++){
                if($char == $char_table[$x]) {
                    $ret .= $x;
                    break;
                }
            }
        }
    }
    return addslashes($ret);
}


?>

我根本不懂,最近怎么回事?为什么全球无法运作?

0 个答案:

没有答案
相关问题