Show Visitors IP Address

software development

#1

I would like to show visitors IP address when they visit my website. I am hoping this will help alieviate some of the problems I am having by those that think they can hide their IP by coming to my site via annoymous sites and such for the purpose of cyber squatting on my website for hours at a time and using up my bandwidth or attempting to hack it.

Does anyone know of a script that uncovers their actual IP address, like what I find in my access log? I want it to come up on my website for them to see when they visit. I’m thinking if they see they aren’t masking their ID, maybe they’ll stop??? htaccess files don’t work for this purpose as their IP changes each time they come on so I can’t keep them out. But I am thinking this way, if they see that I know their IP right away and am logging it…well, maybe they’ll go cause trouble somewhere else? Maybe it will help. Thanks.

S.


#2

Dear Goat,

If you look at my home page (click my username next to ‘posted by’) and go to the folder ip

i.e. example.com/ip

Is that something simple that you want?

You can view the text at example.com/ip/index.phps

(Change the example.com to my homepage)

You will have to change your page suffix to .php of course.
There are many ways to skin this cat/dog/horse/goat (oops!) including server side scripts but this is simple enough.

It is meant as rough and ready so please no complaints from anyone about the shape of the full stops etc!


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#3

If you have a PHP script, then you can use the autoglobal $_SERVER[‘REMOTE_ADDR’] to get the IP of the visitor.

<? echo "Your IP is {$_SERVER['REMOTE_ADDR']}"; ?>

Copy this to a PHP file, and navigate to it. You’ll get a similar page to Norm’s.


#4

The superglobal, as above, will give you the IP address that the packets are originating from, but that doesn’t prevent them from using a proxy.

Is the IP address of the perpetrator(s) changing every time? Is it within one block? Are they causing any actual trouble with the site?

Check out Gordaen’s Knowledge, the blog, and the MR2 page.


#5

If I use

<? echo "Your IP is {$_SERVER['REMOTE_ADDR']}"; ?>

the IP changes if they try using an annoymous or IP blocking site, but of course, my access log still shows their correct IP (it doesn’t change.) I am trying to show them I am collecting their IP so using the annoymous blocking site a dozen times a day isn’t blocking their IP. If I can get the IP to show on the site, figured this would be the most non-intrusive way to do this to my other visitors.

S.


#6

Your access log is going to show the same IP as any web page IP indicator would.

Why not just post the entry:-
“IP address logged”

To be honest anybody seeing their IP address on your website is not going to keep them away. In fact you will be confirming any anonymouse/spoofed IP address they may use. That is why you seldom see the IP address printed on web sites.
Except my website guestbook of course. :smiley:


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#7

Why not just post the entry:-
“IP address logged”

Now that is a great idea. Thanks Norm!

S.


#8

Here’s a common PHP function that checks a few different places for the IP:

function getip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip_addr = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip_addr = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip_addr = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $ip_addr = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $ip_addr = getenv( 'HTTP_CLIENT_IP' ); } else { $ip_addr = getenv( 'REMOTE_ADDR' ); } } return $ip_addr; }

:stuck_out_tongue: Save up to $96 at Dreamhost with 96DOLLARSOFF promo code (I get $1).
Or save $97 with TAKESEILERSCASH.