Jump to content
xisto Community
Sign in to follow this  
lonelym

Does Php Have This? IP Address

Recommended Posts

Is there a function in PHP where I could get the user's IP address or something? I require this function because I plan on restricting a '1 account per IP address' rule on my site.

 

Thanks.

Share this post


Link to post
Share on other sites

It depends on whether or not you want proxy detection.Use PHP's getenv() function to read the value of the environment.Your choices are:- Without proxy detection => REMOTE_ADDR - get the remote client's IP address- With proxy detection => HTTP_X_FORWARDED_FOR - get IP address of proxy server

Share this post


Link to post
Share on other sites

if (getenv("HTTP_CLIENT_IP")){ $ip = getenv("HTTP_CLIENT_IP");}else if(getenv("REMOTE_ADDR")){ $ip = getenv("REMOTE_ADDR");}else if(getenv("HTTP_X_FORWARDED_FOR")){ $ip = getenv("HTTP_X_FORWARDED_FOR");}$ip will be the IP address

Share this post


Link to post
Share on other sites

I plan on restricting a '1 account per IP address' rule on my site.

Hmmmmm, good luck with that if people's IP addresses are going to be dynamically allocated by their ISP's every time they establish a connection.

I suggest you learn more about how ISP's work - and do some reading on DHCP (Dynamic Host Configuration Protocol).

 

Bottom line, it's not as easy as you may think it is.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.