Search code examples
phphtmldatabasetrackinguniqueidentifier

Record visitor's IP in Database


I want to implement something on my website to record the visitor's IP address and put it into a database with a unique id for support and analytics.
Does anyone know of a way to do that, with out changing my pages to PHP, or making the process to crazy to do.

Thanks in advance,
Peter
I will use PHP if needed. Any answer is helpful


Solution

  • You can without having to change the page to a dynamic page, but in the end you need some dynamic web page or web service to write to a database. That dynamic page can be on another website even, but you can not write to a database or file from a static page (not even via javascript).

    In your static page you can add two javascript functions: First get the IP-address using pure Javascript. See: How to get client's IP address using javascript only?

    Then make an ajax call (again from javascript) to a service you create and host somewhere else. Send the ip address to that service and log it.

    Hope this helps