Search code examples
phpmysqlstatisticsipvisitor-statistic

Gather Viewers IP


I want to know how to get the IP address of visitors to my site. I will then put this into an SQL table that will count how many times they visit. I know PHP, JavaScript, HTML, and MySQL so I just need to know what the code for getting a viewer's IP is, I can code the rest myself.

Thanks in advance for the help.


Solution

  • You can get the user's IP address by accessing the $_SERVER array:

     echo $_SERVER['REMOTE_ADDR'];