Jump to content
Sign in to follow this  
rickyboy1982

How do I get and store a users IP address?

Recommended Posts

HiI have not got a script yet but am looking into the best ways to get a usrs Ip address and store it in a database...This is mainly for a member registration script, so i can ban users Ip addresses if needs be.

Share this post


Link to post
Share on other sites

The IP address can be found as the value of $_SERVER['REMOTE_ADDR']. You can then use a standard SQL query to store it in your database.

Share this post


Link to post
Share on other sites

You can use this to try and get the real IP address:

if (getenv('HTTP_CLIENT_IP')) {	$ip_address = getenv('HTTP_CLIENT_IP');}elseif (getenv('HTTP_X_FORWARDED_FOR')) {	$ip_address = getenv('HTTP_X_FORWARDED_FOR');}elseif (getenv('HTTP_X_FORWARDED')) {	$ip_address = getenv('HTTP_X_FORWARDED');}elseif (getenv('HTTP_FORWARDED_FOR')) {	$ip_address = getenv('HTTP_FORWARDED_FOR');}elseif (getenv('HTTP_FORWARDED')) {	$ip_address = getenv('HTTP_FORWARDED');}else {	$ip_address = $_SERVER['REMOTE_ADDR'];}

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  

×