Dobrý den, pokouším se následující kód:
<?php
// Figure out the visitor's IP address
$ip = $_SERVER['REMOTE_ADDR'];
// Establish a database connection (adjust address, username, and password)
$dbh = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("ip2country");
// Create a query string
$country_query = "SELECT country2, country FROM ip2country WHERE ipFrom<=INET_ATON('" . $ip . "') AND ipTo>=INET_ATON('" . $ip . "')";
// Execute the query
$country_exec = mysql_query($country_query);
// Fetch the record set into an array
$ccode_array = mysql_fetch_array($country_exec);
// Close the database connection
mysql_close($dbh);
// Get the country code from the array and save it as a variable
$country_code = $ccode_array['country2'];
// Get the country name from the array and save it as a variable
$country_name = $ccode_array['country'];
// If the database contains a match, print out the country name and country code, otherwise print the IP address
if ($country_code != "") {
echo '<p>The IP-to-Country database contains a match for your ip address: ' . $ip . '</p>';
echo '<p>You are located in ' . $country_name . ', and the country code is ' . $country_code . '</p>';
}else{
echo '<p>Sorry. The IP-to-Country database does not contain a match for your ip address: ' . $ip . '</p>';
}
?>
zprovoznit aby fungoval na php 5.5.12 a mysql 5.6.17
<?php
// Figure out the visitor's IP address
$ip = $_SERVER['REMOTE_ADDR'];
// Establish a database connection (adjust address, username, and password)
$dbh = ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die("Could not connect: " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . ip2country));
// Create a query string
$country_query = "SELECT country2, country FROM ip2country WHERE ipFrom<=INET_ATON('" . $ip . "') AND ipTo>=INET_ATON('" . $ip . "')";
// Execute the query
$country_exec = mysqli_query($GLOBALS["___mysqli_ston"], $country_query);
// Fetch the record set into an array
$ccode_array = mysqli_fetch_array($country_exec);
// Close the database connection
((is_null($___mysqli_res = mysqli_close($dbh))) ? false : $___mysqli_res);
// Get the country code from the array and save it as a variable
$country_code = $ccode_array['country2'];
// Get the country name from the array and save it as a variable
$country_name = $ccode_array['country'];
// If the database contains a match, print out the country name and country code, otherwise print the IP address
if ($country_code != "") {
echo '<p>The IP-to-Country database contains a match for your ip address: ' . $ip . '</p>';
echo '<p>You are located in ' . $country_name . ', and the country code is ' . $country_code . '</p>';
}else{
echo '<p>Sorry. The IP-to-Country database does not contain a match for your ip address: ' . $ip . '</p>';
}
?>
toto bohužel nefunguje, děkuji za rady