Closed Thread Icon

Topic awaiting preservation: Get IP of client in PHP (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11975" title="Pages that link to Topic awaiting preservation: Get IP of client in PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Get IP of client in PHP <span class="small">(Page 1 of 1)</span>\

 
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-04-2002 16:03

Hey everyone,
PsPong.com will include functions that sent out emails. Now I'm in need of a method to retrieve the IP the site is being accessed from. I want to prevent spam. (for example, I don't want to allow more than one account-creation from an ip per 10 minutes...)
I didn't find it in the phpmanual, but I'm pretty sure, I'm looking at the wrong places :-(

Please help,

Tyberius Prime

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 01-04-2002 17:47

if (getenv(HTTP_X_FORWARDED_FOR)) { $onlineip = getenv(HTTP_X_FORWARDED_FOR); }
else { $onlineip = getenv(REMOTE_ADDR); }

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-04-2002 20:54

I would suggest you to only check REMOTE_ADDR environment variable. HTTP_X_FORWARDED_FOR variable can contain all kinds of data (IP address, error message like "[unknown origin]", etc) and it was giving me troubles with sessions...


jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 01-07-2002 17:13

Just thought I'd add that you can reference the variables like so:

$HTTP_SERVER_VARS['REMOTE_ADDR']
$HTTP_SERVER_VARS['REMOTE_HOST']

REMOTE_HOST will give you the domain lookup of the IP.

Is there a consensus on the 'better' way to access environment variables? (ie. getenv() vs $HTTP_SERVER_VARS[])

Also, I'm sure you know this, but I always find have a test.php file at my server root with just the phpinfo() function in it is very useful for getting this sort of information...

-jiblet

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-07-2002 17:21

thanx, everyone.

Of course I have a file that shows phpInfo().
But it for sure wasn't the place I was looking in. I was trying to find this in the PHP manual. (a search for IP didn't turn up anything).
It's kind of 'hidden' knowledge :-)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-07-2002 18:27

when in doubt just make a page like so

<?
phpinfo()
?>

That way you don't have to find one.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-07-2002 18:31

the problem was, I wasn't looking for phpinfo at all. I was looking for a function to get the clients IP. who knows why they hide it in an enviromental variable...

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 01-07-2002 18:32

Jiblet, I prefer to use getenv() for two reasons...

1. I don't have to declare $HTTP_SERVER_VARS as global in each function where I would need to get some environment variable.
2. Starting from new PHP 4.1.0 version, $HTTP_GET_VARS (as well as all other predefined $HTTP_* environment variables) are deprecated, and if you use new global $_SERVER variable your script wouldn't work in older versions of PHP (where getenv() would work).

Tyberius Prime, IP address is not hidden. Web servers get IP address through HTTP header, and PHP puts everything that's in header in its own predefined $HTTP_* variables...




[This message has been edited by mr.maX (edited 01-07-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu