Get country code from JavaScript to PHP
Posted: 15 Nov 2019, 13:23
Chief I have a problem to get the countrycode into my sql-statement.
Please help me out....
This script is to detect the countrycode
I try with this simple php code to detect $country_code1
This $country_code1 i try to get the result into this sql-document
Please help me out....
This script is to detect the countrycode
Code: Select all
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
function writeMessage() {
if (language.indexOf('en') > -1) document.write('US');
else if (language.indexOf('nl') > -1) document.write('NL');
else document.write('');
}
// End -->
</script>
<script>writeMessage();</script>
Code: Select all
<?php
$country_code1 = '<script>writeMessage();</script>';
?>
Code: Select all
<?php
// connect to the "tests" database
$conn = new mysqli('127.0.0.1', 'ip_ban', '123456', 'ip_ban');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// SELECT sql query
$sql = "SELECT `ip_adress`, `country_code` FROM `ip_ban` WHERE ip_adress='$ip' or country_code='$country_code1' LIMIT 1 ";
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
// output data of each row from $result
while($row = $result->fetch_assoc()) {
echo ' <p> '. $row['ip_adress']. ' '. $row['country_code']. '
Your Banned
<br>' ;
}
}
else {
echo '';
}
$conn->close();
?>