Skip to content
Advertisement

How do I Save IP’s of Those Who Visit My Website to logs.txt?

I have a website with which I want to record the ip’s of those who visit it. Now, I think I have some code that will do the job (I got this from here):

JavaScript

What I want this to end up doing is saving the ip address and the date of everyone who visits my website to a log.txt file. I think that you use the fwrite command to do this, but I really have no idea. I don’t know anything about php, so I am looking for a book (any recommendations would be well appreciated). There are a lot of seemingly outdated or straight up wrong tutorials for php out there and I would love to avoid those.

Any help appreciated!

Advertisement

Answer

You can do it with file_put_contents(). Don’t forget to use a lock to avoid data loss.

JavaScript

https://php.net/file-put-contents

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement