I would think your web server already logs this info. Might be better to parse the log file, rather than to keep a redundant server log.
But sure, you can do it. You can get peoples IP from this superglobal
$_SERVER["REMOTE_ADDR"]
Then, just wite it to a file outside of web root. That would prevent web access to the log file.
You could even include this logger transparently with a little edit of your php.ini file.