PHP Environmental Variables
Hello
How do I return a users IP address and referring page?
I'm writing a security section of a script of mine, and I need to log IPs and referring pages, so there aren't multiple users on one IP, and that they are in deed coming from my site to this script.
Thanks!
Mark Hensler posted this at 17:38 — 1st December 2001.
He has: 4,048 posts
Joined: Aug 2000
You can get a list of all vars here:
PHP Predefined Variables
Or by looking at phpinfo()
Apache variables
$HTTP_REFERER
$REMOTE_ADDR
nike_guy_man posted this at 03:39 — 2nd December 2001.
They have: 840 posts
Joined: Sep 2000
Ok
I'm using a router, so $REMOTE_ADDR returns 192.168.1.1
Is there any way to get around this?
Thanks
Mark Hensler posted this at 08:02 — 2nd December 2001.
He has: 4,048 posts
Joined: Aug 2000
I've noticed that on my network too. It seems to return 192.168.1.1 because your 'remote computer' is on the LAN. If you access the site from outside your LAN (on the WAN side), then you should get a real IP.
I've not found a way around this. It wasn't crucial for me at the time, so I didn't spend too much time researching it. If you find something, let us know.
Mark Hensler
If there is no answer on Google, then there is no question.
mairving posted this at 20:26 — 2nd December 2001.
They have: 2,256 posts
Joined: Feb 2001
That's a weird one. Mine returns the IP address of the remote machine, not the router IP.
nike_guy_man posted this at 20:42 — 2nd December 2001.
They have: 840 posts
Joined: Sep 2000
Ok...
I had 3 friends run this script.
One was on a LAN and it gave the 192.168.1.1
Another was on a LAN and it gave his internal IP of 192.168.1.22
The last one was on a dialup, and it returned his IP.
Mark Hensler posted this at 01:09 — 3rd December 2001.
He has: 4,048 posts
Joined: Aug 2000
*shivers*
Freaky weird!
Maybe the routers are handling it differently?
My router is the Linksys BEFSR41, and it's acting as the DHCP server. Anyone use a different setup?
Mark Hensler
If there is no answer on Google, then there is no question.
mairving posted this at 02:03 — 3rd December 2001.
They have: 2,256 posts
Joined: Feb 2001
Yeah, well the dialup should return the IP of the ISP. The other differences probably would be in the use of proxy servers.
Wil posted this at 10:20 — 3rd December 2001.
They have: 601 posts
Joined: Nov 2001
Here is what I found on the issue.
However some web servers can also intercept the ENV VAR REMOTE_PROXY to determine if the user is accessing through a proxy server, and if they are, you can do a simple check to see if the REMOTE_ADDR is set to the proxy or the IP.
Cheers
- wil
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.