Sabrin
asked on
less code
hello,
is there a way of doing this with less code!!
if (geoip_country_code_by_add r($gi, $ip) == CN){
exit;
}else if (geoip_country_code_by_add r($gi, $ip) == RU){
exit;
}else if (geoip_country_code_by_add r($gi, $ip) == SK){
exit;
}else if (geoip_country_code_by_add r($gi, $ip) == TR){
exit;
}else if (geoip_country_code_by_add r($gi, $ip) == YE){
exit;
}
I have around 50 country codes!
is there a way of doing this with less code!!
if (geoip_country_code_by_add
exit;
}else if (geoip_country_code_by_add
exit;
}else if (geoip_country_code_by_add
exit;
}else if (geoip_country_code_by_add
exit;
}else if (geoip_country_code_by_add
exit;
}
I have around 50 country codes!
ASKER
didnt work
Another way is:
switch(geoip_country_code_ by_addr($g i, $ip))
{
case 'CN':
case 'RU':
case 'SK':
case 'TR':
case 'YE':
exit;
break;
}
Roonaan's way is better, unless you need to do different things for different codes.
switch(geoip_country_code_
{
case 'CN':
case 'RU':
case 'SK':
case 'TR':
case 'YE':
exit;
break;
}
Roonaan's way is better, unless you need to do different things for different codes.
are CN/RU/SK/TR/YE strings or constants?
Might need to be something different if they where constants
if(in_array(geoip_country_ code_by_ad dr($gi, $ip), array(CN,RU,SK,TR,YE)) {
exit();
}
-r-
Might need to be something different if they where constants
if(in_array(geoip_country_
exit();
}
-r-
ASKER
i dont know but its not working
>> didnt work
Any more details as to why it didn't work? any errors for example?
Any more details as to why it didn't work? any errors for example?
ASKER
no errors no nothing,
but when I use the code that works I get this
Notice: Use of undefined constant
but when I use the code that works I get this
Notice: Use of undefined constant
ASKER
Notice: Use of undefined constant US - assumed 'US' in /home/file.php on line 25
line 25 = if (geoip_country_code_by_add r($gi, $ip) == US){
line 25 = if (geoip_country_code_by_add
ASKER
like this i dont get any notices
if (geoip_country_code_by_add r($gi, $ip) == 'US'){
if (geoip_country_code_by_add
ASKER
this is working
if (geoip_country_code_by_add r($gi, $ip) == 'CN'||'US'){
if (geoip_country_code_by_add
ASKER
what im trying here is that if its (country code) exit and dont show the site
ASKER
What's the output of geoip_country_code_by_addr ($gi, $ip) ?
Also, what's the output of:
echo CN;
The specific values might be causing problems.
Also, what's the output of:
echo CN;
The specific values might be causing problems.
ASKER
what output? theres no output!
GeoIP.dat its just a database of IPs
geoip.inc has all the country codes with numbers
$gi checks to see if $ip is from a country lets say US and if its from US then its not allowed!
if (geoip_country_code_by_add r($gi, $ip) == 'CN'){
echo "not allowed";
exit;
}
GeoIP.dat its just a database of IPs
geoip.inc has all the country codes with numbers
$gi checks to see if $ip is from a country lets say US and if its from US then its not allowed!
if (geoip_country_code_by_add
echo "not allowed";
exit;
}
County codes are strings, and Roonan's code should work.
Also, "Notice: Use of undefined constant" is an error. In your original code, there were no quotes around the country codes.
Also, "Notice: Use of undefined constant" is an error. In your original code, there were no quotes around the country codes.
What does the below code give you? The in_array should work fine syntactically, but reraly depends on the output of your geoip function.
echo '['.geoip_country_code_by_ addr($gi, $ip).']';
-r-
echo '['.geoip_country_code_by_
-r-
ASKER
echo '['.geoip_country_code_by_ addr($gi, $ip).']';
[US]
[US]
ASKER
sorry this doesnt work correctly
if (geoip_country_code_by_add r($gi, $ip) == 'CN'||'US'){
if (geoip_country_code_by_add
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
exit();
}