I have a IP range php function that responds with 1 if ip is in range.
Php:
<?
$ip = $_SERVER['REMOTE_ADDR'];
$public_ip_ranges = array();
$range = (object) array();
$range->name = 'Barclays';
$range->lower = '141.228.0.0';
$range->upper = '141.228.255.255';
$public_ip_ranges[] = $range;
$range = (object) array();
$range->name = 'Incisive Media';
$range->lower = '10.1.0.0';
$range->upper = '10.1.255.255';
$public_ip_ranges[] = $range;
$range = (object) array();
$range->name = 'Barcap';
$range->lower = '146.127.0.0';
$range->upper = '146.127.255.255';
$public_ip_ranges[] = $range;
if (($lngIP=ip2long($ip)) < 0) $lngIP += 4294967296;
foreach ($public_ip_ranges as $ip_range) {
if (($lngLow=ip2long($ip_range->lower)) < 0) $lngLow += 4294967296;
if (($lngHigh=ip2long($ip_range->upper)) < 0) $lngHigh += 4294967296;
if($lngIP >= $lngLow and $lngIP <= $lngHigh) {
echo 1;
}
}
?>
I have ajax referring to this file but what i would like to do is if PHP function echo's 1 then display x text else display Y text.
Ajax:
$.ajax( {
url: "/microsub.php",
method: 'GET',
success: function (data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
} );
So I would like to take the response from the php (which should echo 1 if in range) and display text alert else if not display different text alert
success: function(data)part:if(data == 1){ // do something because the IP is in range } else { // do another thing because the IP is not in range }. It's like Marc says, though, we need your code to help you with.