在数据库中保存IP [英] Save IP in database

查看:105
本文介绍了在数据库中保存IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户登录时,我想将他们的IP保存在数据库中。我该怎么办? MySQL字段最适合使用哪种类型? PHP代码如何获得IP看起来像?

When a user logs in I want to save their IP in the database. How would I do that? What type is best to use for the MySQL field? How would the PHP code to get IP look like?

我正在考虑将其用作登录/会话内容的额外安全功能。我正在考虑检查用户从数据库登录的IP,用户现在已将IP作为检查会话的补充。因此,它首先检查会话,然后检查您是否有有效的IP。

I'm thinking of using it as an extra security feature for the login/session stuff. I'm thinking of checking the IP the user logged in with from the DB with the IP the user have now as addition to checking the session. So that it first check the session, and then check if you have a valid IP.

这是一个很好的额外功能吗?还有什么其他方法可以让它更安全?

Is that a good extra feature? And what other things can I do to make it more secure?

推荐答案

看看mysql中的INET_NTOA和INET_ATON函数。它们在点分表示法IP地址之间转换为32位整数。这允许您以4个字节而不是15个字节存储IP。确保使用unsigned int而不是signed int。

Have a look at the INET_NTOA and INET_ATON functions in mysql. They convert between dotted notation IP address to 32 bit integers. This allows you to store the IP in just 4 bytes rather than a 15 bytes. Make sure you use an unsigned int and not a signed int.

这篇关于在数据库中保存IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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