A blog for technology, SEO tips, website development and open source programming.

Get visitor IP address in PHP

0 805

PHPThere are several cases that that we need to track the ip address of visitors on websites either for validation, security, spam prevention etc. Using php it’s easy to get visitor ip address. The post will demonstrate how you can get the ip address using PHP.

No Proxy detection


But If a user access the website via a proxy server $_SERVER[‘REMOTE_ADDR’] will return the ip address of proxy server not of the proxy user. So we have two methods here to get the ip address of a user.

Using $_SERVER

$_SERVER is an array created by the web server, that contains the server variables.

Using getenv() function

getenv() function is used to read the value of the environment variables in PHP. This function is useful when visitors are using the proxy server to access the site.

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More