【发布时间】:2016-12-04 14:20:36
【问题描述】:
所以我有一个网站,人们可以使用密码访问购买。
Example:
http://www.MyWebsite.com/?pass=YourPassword
我想知道如何使用他们使用的 ?pass 将 ip 记录在 .txt 文件中。 这样我就可以看到在什么密码上使用了哪些 ip。 任何帮助,将不胜感激! 提前致谢。
【问题讨论】:
所以我有一个网站,人们可以使用密码访问购买。
Example:
http://www.MyWebsite.com/?pass=YourPassword
我想知道如何使用他们使用的 ?pass 将 ip 记录在 .txt 文件中。 这样我就可以看到在什么密码上使用了哪些 ip。 任何帮助,将不胜感激! 提前致谢。
【问题讨论】:
首先:通过 url 传递密码是非常糟糕的主意。但是让我们假设您正在通过$_GET['pass'] 传递一些其他数据。
这里描述了如何获取用户的IP地址:https://stackoverflow.com/a/3003233/3845412
你的脚本应该做这样的事情:
$ip = your_function_that_gets_user_ip();
$pass = $_GET['pass'];
file_put contents('file.txt', implode(',', [$pass, $ip]) . PHP_EOL, FILE_APPEND);
这使得file.txt 使用如下格式:
127.0.0.1,secret
192.168.137.1,foopassword
【讨论】: