PDA

View Full Version : IP & Browser Guide



LegendOfNoob
17-11-2007, 05:31 PM
kso, a while back on here someone said they needed the IP & Browser Script
well this is a guide i found Wayy back i got some info i dont beleive it was on this forum i know alot of people look for this at times again i say
i was looking in old folders and found where i wrote it down this is not complety mine i am releasing it as help

Get Users IP:
PHP Code:
<?php
echo("Your IP: ");
echo $_SERVER['REMOTE_ADDR'];
?>


Get Users Browser:
PHP Code:
<?php
echo("Your Browser: ");
echo $_SERVER['HTTP_USER_AGENT'];
?>

if your wanting to log to further know what your devolping & Requirements of your coding is im sure you can add a log into the code to know whitch browsers are used the most to be more compatible with your users
o one last thing

This Script Logs The IP Address & i beleive tells you how to ban aswell

1. Enter this code onto the index of your website, this will log everyone who enters and put their hostname and IP address into a text file. Its a php code so save the index file as a php file and make sure it goes at the top of the page.


<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip = $_SERVER['REMOTE_ADDR'];
$old = file_get_contents('logger.txt');
// Add more local IP's if you want using the method i used below...
if($ip!="192.168.0.2"||$ip!="192.168.0.3"||$ip!="192.168.0.4"){
file_put_contents('logger.txt', $old.'
Hostname : '.$hostname.'
IP : '.$ip.'
');
}
else{
echo 'Error : Local IP - Not logged';
}
if($ip=="BLOCKED IP ADDRESS HERE"||$hostname=="BLOCKED HOSTNAME HERE"||$ip=="BLOCKED IP2 ADDRESS HERE"||$hostname=="BLOCKED HOSTNAME2 HERE"){
echo '<meta http-equiv="refresh" content="0;url=http://www.google.com" />';
}
?>
2. This will then put all their data into logger.txt. It allso dosnt log local IP addresses (whitch if you run your site from your own pc or somthing is usefull)
Now after the ip address is logged notice someone breaking the rules
create a .htacess
No name make sure you edit the minate you create or make it then upload
9/10 times it will upload to your server then disapear only seen in FTP

First Our the main function



# allow all except those indicated here
<Files *>
order allow,deny
allow from all
deny from 12.345.67.890
deny from .*domain\.com.*
</Files>

Then Our Deny IP Function


# deny all except those indicated here
<Files *>
order deny,allow
deny from all
allow from 12.345.67.890
allow from .*domain\.com.*
</Files>


Now we will block domains whitch comes in good to block Proxies



# block visitors referred from indicated domains
RewriteEngine on
RewriteCond %{HTTP_REFERER} offendingdomain1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} offendingdomain2\.com [NC,OR]
RewriteRule .* - [F]

Then Save make sure its .htacess with no .txt if your using notepad
if you cant change it instead use a ftp right click & change the name with no .txt

Now your set up basically there
(note: i created the .htacess though its simple its a nice addiction for a full
guide)

If you see any errors feel free to point them out

Want to hide these adverts? Register an account for free!