johnsamir
Advanced OT User
Hello
I use ZnoteAcc 1.5
Would like that when a player access to register section it would auto detect his country and will choose it right away, if would be possible to make that country the only available option would be cool
so what i've done so far is this
check_country.php
located at
then in register.php located at
added this script
and i changed country filling form from this
to this
no errors directly in console but if i press f12 i get all these errors
i already have jquery-1.10.2.min.js installed in C:\xampp\htdocs\engine\js and in C:\xampp\htdocs\layout too
also i checked check_country.php via browser and seems to be working http://127.0.0.1/layout/sub/check_country.php
API URL: http://ip-api.com/json/152.172.xxx.246{"country_code":"xl","country_name":"China"}
can somebody lend me a hand?
I use ZnoteAcc 1.5
Would like that when a player access to register section it would auto detect his country and will choose it right away, if would be possible to make that country the only available option would be cool
so what i've done so far is this
check_country.php
Lua:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once '../../engine/init.php';
require_once '../../engine/function/users.php';
require_once dirname(__FILE__) . '/../../config.countries.php';
//require_once $_SERVER['DOCUMENT_ROOT'] . '/config.countries.php';
//require_once '../../engine/init.php';
//require_once $_SERVER['DOCUMENT_ROOT'] . '/engine/init.php';
//require_once $_SERVER['DOCUMENT_ROOT'] . '/engine/function/users.php';
//require_once '../../engine/function/users.php';
//require_once '../../engine/function/users.php';
//require_once 'config.countries.php'; // Adjust the path if necessary
//require_once $_SERVER['DOCUMENT_ROOT'] . '/config.countries.php';
// Get the user's public IP address
$user_ip = file_get_contents('https://api.ipify.org');
// Fetch the user's location data from ip-api.com
$ipapi_url = "http://ip-api.com/json/$user_ip";
echo "API URL: $ipapi_url"; // Echo the URL for debugging
$location_data = file_get_contents($ipapi_url);
if ($location_data === false) {
$response = ['error' => 'Unable to fetch location data'];
} else {
$location_data = json_decode($location_data, true);
$country_code = $location_data['countryCode'] ?? ''; // Default to empty string if not found
$response = [];
// Validate if the country code exists in your countries config
if (!empty($country_code) && isset($config['countries'][strtolower($country_code)])) {
$response['country_code'] = strtolower($country_code);
$response['country_name'] = $config['countries'][strtolower($country_code)];
} else {
// If country code is not found or invalid, return an error
$response['error'] = 'Unable to detect your country';
}
}
header('Content-Type: application/json');
echo json_encode($response);
?>
Code:
C:\xampp\htdocs\layout\sub
Code:
C:\xampp\htdocs
Code:
$(document).ready(function(){
// Function to get user's country based on IP
function getUserCountry() {
$.ajax({
url: 'check_country.php',
type: 'GET',
success: function(response) {
if (response.country_code) {
// Add an option for the detected country
$('#countrySelect').append('<option value="' + response.country_code + '" selected="selected">' + response.country_name + '</option>');
}
},
error: function(xhr, status, error) {
console.error('Error:', error);
}
});
}
// Call the function to get user's country on page load
getUserCountry();
});
</script>
Code:
<!-- Rest of your form fields -->
<b>Country:<br></b>
<select name="flag">
<option value="">(Please choose)</option>
<?php
foreach(array('pl', 'se', 'br', 'us', 'gb', ) as $c)
echo '<option value="' . $c . '">' . $config['countries'][$c] . '</option>';
echo '<option value="">----------</option>';
foreach($config['countries'] as $code => $c)
echo '<option value="' . $code . '">' . $c . '</option>';
?>
</select>
</li>
Code:
<li>
<!-- Rest of your form fields -->
<b>Country:<br></b>
<select name="flag" id="countrySelect">
<option value="">(Please choose)</option>
</select>
</li>
Code:
jquery-1.10.2.min.js:8706
GET http://127.0.0.1/check_country.php 404 (Not Found)
send @ jquery-1.10.2.min.js:8706
ajax @ jquery-1.10.2.min.js:8136
getUserCountry @ register.php:494
(anonymous) @ register.php:510
fire @ jquery-1.10.2.min.js:3048
fireWith @ jquery-1.10.2.min.js:3160
ready @ jquery-1.10.2.min.js:433
completed @ jquery-1.10.2.min.js:104
register.php:504 Error: Not Found
error @ register.php:504
fire @ jquery-1.10.2.min.js:3048
fireWith @ jquery-1.10.2.min.js:3160
done @ jquery-1.10.2.min.js:8237
callback @ jquery-1.10.2.min.js:8778
XMLHttpRequest.send (async)
send @ jquery-1.10.2.min.js:8706
ajax @ jquery-1.10.2.min.js:8136
getUserCountry @ register.php:494
(anonymous) @ register.php:510
fire @ jquery-1.10.2.min.js:3048
fireWith @ jquery-1.10.2.min.js:3160
ready @ jquery-1.10.2.min.js:433
completed @ jquery-1.10.2.min.js:104
34
Third-party cookie will be blocked. Learn more in the
i already have jquery-1.10.2.min.js installed in C:\xampp\htdocs\engine\js and in C:\xampp\htdocs\layout too
also i checked check_country.php via browser and seems to be working http://127.0.0.1/layout/sub/check_country.php
API URL: http://ip-api.com/json/152.172.xxx.246{"country_code":"xl","country_name":"China"}
can somebody lend me a hand?