/    Sign up×
Community /Pin to ProfileBookmark

Banning specific IP addresses from accessing my web site

HI everyone ,
[COLOR=”DarkSlateBlue”]Sorry for bothering ,
But I’m a PHP developer and I want to ban specific country users from accessing my web site .. does any one knows how to do it ? and where can i get the country range of IPs ?- and please I want to do it through some coding .. and not through the .htaccess or other server files . [/COLOR]

thanx alot
?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 18.2007 — What country do you want to ban and why?
Copy linkTweet thisAlerts:
@m_sahalyauthorMar 18.2007 — I want to ban all the countries except Bahrain .. because the web site is for the bahrain health ministry and they want to make the web site for their population only .
Copy linkTweet thisAlerts:
@bokehMar 18.2007 — Geography and Nationality are not synonomous. What is gooing to happen if one of the populous is not in Bahrain when trying to access the site?
Copy linkTweet thisAlerts:
@m_sahalyauthorMar 18.2007 — Bokeh ,

thanx alot for considering my posts .. but to your knowledge I know exactly what i'm asking for . and I just wanna check for the IP only when the user is registering himself to our web site . thus ,registeration is limited only to Bahrain people . but any one else is still able to review the site , but will not be able to register with it . and after registeration he can login to his account from any country all over the world .

Now , would you please let me know how can I achieve this . even if you found that the whole matter is not logical ?!!

Thanx
Copy linkTweet thisAlerts:
@bokehMar 18.2007 — Maybe something like this. Bear in mind IP ranges are in flux and you would need to keep the data up to date.[code=php]function is_bahrain()
{
static $pairs = array(
array('1076299504','1076299519'),
array('1076303360','1076303391'),
array('1076304160','1076304191'),
array('1080958208','1080958463'),
array('1080958720','1080958975'),
array('1080960256','1080960511'),
array('1080968192','1080968447'),
array('1080969472','1080969727'),
array('1210070864','1210070871'),
array('1296400384','1296433151'),
array('1348005888','1348009983'),
array('1348456448','1348460543'),
array('1358008320','1358012415'),
array('1358630912','1358635007'),
array('1360129536','1360130047'),
array('1360400384','1360404479'),
array('1365164032','1365168127'),
array('1388453888','1388462079'),
array('1401436160','1401438207'),
array('1426030592','1426046975'),
array('1436450816','1436452863'),
array('1475096576','1475098623'),
array('1475119104','1475121151'),
array('1475198976','1475201023'),
array('1476157440','1476165631'),
array('1486348288','1486350335'),
array('1495046144','1495048191'),
array('1495252992','1495255039'),
array('1502871552','1502887935'),
array('1505656832','1505665023'),
array('3250326528','3250327039'),
array('3250348032','3250356223'),
array('3252429776','3252429807'),
array('3510471008','3510471039'),
array('3510472632','3510472671'),
array('3510474240','3510474271'),
array('3519475712','3519476223'),
array('3560942292','3560942295'),
array('3560943672','3560943672'),
array('3641827328','3641835519')
);

$int = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));

foreach($pairs as $pair)
{
if($pair[0] <= $int && $int <= $pair[1])
{
return true;
}
}
return false;
}[/code]
Copy linkTweet thisAlerts:
@m_sahalyauthorMar 18.2007 — Thanx alot bokeh ,

I appreciate your help .. but can you send me a list of the coutries IPs , just for future uses .I'll be grateful to you for this .
Copy linkTweet thisAlerts:
@bokehMar 18.2007 — Just do a search, there are lots of online databases available (but I'm not one of them).
Copy linkTweet thisAlerts:
@m_sahalyauthorMar 18.2007 — Ok thanx again
×

Success!

Help @m_sahaly spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...