记录用户的IP地址,日期和时间 [英] Log user ip address, date and time

查看:221
本文介绍了记录用户的IP地址,日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以添加一个简单的脚本或代码片段来保存每个访问者的日志,他们点击页面的日期和时间以及IP地址?
什么是最好的方法... javascript,php,别的什么?

Is there a simple script or piece of code I can add to my page to keep a log of every visitor, the date and time they hit the page and IP address? And what would be the best way to do this... javascript, php, something else?

编辑:

哎哟...

这是发生了什么......当我使用FileZilla访问我的服务器时,有所有域名(约20个)我像我的domain.com一样被记录,所以我找到了我需要的那个并检查了日志,但它主要是搜索引擎。

Here is what happened... When I went to my server with FileZilla there were all the domain names (about 20) I have being logged like my domain.com so I found the one I needed and checked the logs but it was mainly search engines.

但我刚刚回去,碰巧向下滚动到看不见的东西,所有的域名再次出现在www.mydomain.com前面的www当然,那里的日志很大,并且我需要的每一点信息。

But I just went back and happened to scroll down to stuff that was out of view and there were all the domain names again with www in front like www.mydomain.com and of course the logs in there are huge and have every single bit of info I need.

这是因为我找到了我正在寻找的mydomain.com当然我停止了看。我不知道或者看到还有其他一些看法......诚实的错误。

This happened because I found what I was looking for mydomain.com and of course I stopped looking. I didn't know or see there was a whole other set out of view... honest mistake.

我仍在使用该代码因为它很好而且很小,日志非常庞大,需要花费数小时才能下载和查看。

I am still using that code because it is nice and small, the logs are freakin' huge and take hours to download and look at.

推荐答案

$line = date('Y-m-d H:i:s') . " - $_SERVER[REMOTE_ADDR]";
file_put_contents('visitors.log', $line . PHP_EOL, FILE_APPEND);

还要考虑记录 $ _ SERVER ['REQUEST_URI'] 或其他有趣的信息,可能采用@Day概述的更标准格式。

Consider also logging $_SERVER['REQUEST_URI'] or other interesting information, possibly in a more standard format as outlined by @Day.

这篇关于记录用户的IP地址,日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆