It happened at the webmasters that their sites come both users and spam robots. If the first visit to the site to find specific information, the second will certainly give the address e-mail'ov.
The so-called fluttery that simply by doing nothing or little intelligence and rubble you would like news, articles obtuse vocabulary. Well, message forums, apparently not related to the theme of the topic.
This is inevitable as the fact that after night comes day and vice versa. But this must be addressed - otherwise, your honest users do lose interest in your site - you can not doubt.
The most simple method to counter this phenomenon - it banned visitors to ip. Simply put, close their access to your site. This method though not perfect protection, but about 90% protection, it will provide to you. but this is better than nothing.
Then look at how this technology to protect works in practice and how it can be implemented in php.
For the case
To begin, we need to get a list of ip-addresses, which will not have access to our site. Still need to use arrays and loops - that's where we and useful php.
Read more - more
For ip-address of the visitor can use super global $ _SERVER [‘REMOTE_ADDR'].
In php, this is implemented as follows:
<? php $ ip = $ _SERVER [ 'REMOTE_ADDR'];
And now investigate with the other variables of our mini-script. Create an array ($ ban), which put all ip:
$ ban = array ('333 .333.333.333 ','111 .111.111.111');
As you can see, ip must be placed in single quotes and separated from each other with a comma (all simply and clearly - what I like php)
In the following variables ($ count) will be recorded the number of those ip:
$ Count = count ($ ban);
What this all you want - read on.
What we have:
1) IP address of a visitor - the variable $ ip;
2) prohibited by an array of IP-addresses - $ ban;
3) The number of elements of the array - $ count.
All elementarily simple - take care and check the address $ ip with a list of banned - as well as we can have more than one, then that would circumvent the entire array addresses.
This work is easily done for us cycle for:
for ($ i = 0; $ i <$ count; $ i + +) (
if ($ ip == $ ban [$ i]) (die ( "I'm sorry, you've been banned. $ ip"))?>
So it turns out that if the verifiable address matches one of our "bad", then we will know the holder - I'm sorry, you've been banned. 68.225.34.86.
Here is the entire script entirely - this is for those who are lazy to collect it by parts of the article:
<? php
$ ip = $ _SERVER [ 'REMOTE_ADDR'];
$ ban = array ('333 .333.333.333 ','68 .225.34.86');
$ count = count ($ ban);
for ($ i = 0; $ i <$ count; $ i + +) (
if ($ ip == $ ban [$ i]) (die ( "I'm sorry, you've been banned. $ ip")



)?>
Reply With Quote
Copyright Techfuels
Bookmarks