以下は、私が自分のサイトで使用しようとしているものです。この php ページは、Firefox と Chrome で問題なく表示されます。
何らかの理由で IE で動作していないようです (8 と 9 でテスト済み)。ここで何が問題なのか本当にわかりません。
IE8 で表示されるエラーは「有効な 2 次元配列ではありません」です。これは、Google がホストする .js から来ているようです。
なぜこれが IE8 でのみ発生し、Chrome や Firefox では発生しないのでしょうか?
<?php
// Top snippet of code comes from:
// www.ip2nation.com/ip2nation/Sample_Scripts/Output_Full_Country_Name
// and adapted as necessary.
$server = 'sanitized'; // MySQL hostname
$username = 'sanitized'; // MySQL username
$password = 'sanitized'; // MySQL password
$dbname = 'sanitized'; // MySQL db name
// 1 address per line, or feed with a DB if you're feeling clever.
$lines = file('blocklist.txt');
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$bans = array();
foreach ($lines as $lnum => $line)
{
$l=rtrim($line);
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$l.'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($cc) = mysql_fetch_row(mysql_query($sql));
if ($cc != "")
if(empty($bans["$cc"]))
{
$bans["$cc"] = 1;
}
else
{
$bans["$cc"]++;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<script type='text/javascript' src='https://www.google.com/jsapi'>
</script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks'],
<?php
foreach ($bans as $key => $value)
print"['$key', $value],\n";
?>
]);
var options = {
backgroundColor : '#baecfd',
colors : ['#FFFFFF', '#FF0000']
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
<title></title>
<style type="text/css">
div.c1 {width: 900px; height: 500px;}
</style>
</head>
<body>
<div id="chart_div" class="c1"></div>
</body>
</html>
IE でコンパイルしたときのコードは次のとおりです。
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks']
['Japan', 11]
['United States', 45]
['Argentina', 1]
['Brazil', 1]
['Bosnia and Herzegovina', 1]
['Germany', 4]
['France', 2]
['Russia', 5]
['China', 24]
['Thailand', 1]
['New Zealand (Aotearoa)', 1]
['Turkey', 1]
['Korea (South)', 6]
['Panama', 2]
['Taiwan', 6]
['Canada', 14]
['Luxembourg', 1]
['United Kingdom', 1]
['Philippines', 1]
['Singapore', 3]
['Switzerland', 2]
['Hong Kong', 2]
]);
var options = {
backgroundColor : '#25383c',
colors : ['#FFFFFF', '#FF0000']
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Chrome でコンパイルしたときのコードは次のとおりです。
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country','Blocks'],
['Japan', 11],
['United States', 45],
['Argentina', 1],
['Brazil', 1],
['Bosnia and Herzegovina', 1],
['Germany', 4],
['France', 2],
['Russia', 5],
['China', 24],
['Thailand', 1],
['New Zealand (Aotearoa)', 1],
['Turkey', 1],
['Korea (South)', 6],
['Panama', 2],
['Taiwan', 6],
['Canada', 14],
['Luxembourg', 1],
['United Kingdom', 1],
['Philippines', 1],
['Singapore', 3],
['Switzerland', 2],
['Hong Kong', 2],
]);
var options = {
backgroundColor : '#25383c',
colors : ['#FFFFFF', '#FF0000']
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>