Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!isset($_SESSION)) {
- //session_start();
- }
- // getting informations about user
- $useragent = $_SERVER['HTTP_USER_AGENT'];
- $bots = "google msnbot lycos scooter fast-webcrawler technorati yahoo bloglines blogsearch gigabot";
- function get_ip(){
- // check if the user's information is already in file
- $ip = getenv("REMOTE_ADDR");
- $file = "ipb.txt";
- $fr = fopen($file, "r") or exit("Fisier indisponibil!");
- $data = fread($fr, filesize($file));
- fclose($fr);
- if (strpos($data,$ip) == FALSE) {
- // writing the user's information in a file
- $fw = fopen($file, "a") or exit("Fisier indisponibil!");
- fwrite($fw, "\n" . $ip . "; ");
- fclose($fw);
- }
- else {
- $ippos = strpos($data,$ip);
- $pv = strpos($data,';',$ippos);
- $n = strlen($data);
- $j==0;
- for($i=0; $i<$n; $i++){
- if($i==$pv+2){
- $datan[$j]="*";
- $datan[$j+1]=$data[$i]; $j+=2;
- }
- else{
- $datan[$j]=$data[$i]; $j++;
- }
- }
- $frw = fopen($file, "w") or exit("Fisier indisponibil!");
- for($i=0;$i<$j;$i++){
- fwrite($frw, $datan[$i]);
- }
- fclose($frw);
- $datan='';
- }
- }
- // check if the user it's a crawler bot
- if (strpos($bots,$useragent) == FALSE) {
- // anti flood protection
- if($_SESSION['last_session_request'] > time() - 4){
- $_SESSION['last_session_request'] = time();
- header("location: /antiflood.html"); get_ip();
- exit;
- }
- }
- $_SESSION['last_session_request'] = time();
- ?>
Add Comment
Please, Sign In to add comment