dsf5989 2010-05-28 00:00
浏览 18
已采纳

创建登录系统的最佳方法是什么?

I am always wondering that the login systems I have created is vulnerable to attacks or not.

As many other programmers I also use sessions to hold a specific token token to know the login status. Cookies to hold the username or even sometime saved status.

What I am wondering is, Is this the right way? Is there any approach better than this?

  • 写回答

3条回答 默认 最新

  • doufu9947 2010-05-28 01:08
    关注

    You could create your own custom checks on the session. Make sure it's created by the same user agent and from the same IP address.

    Other than that, sessions are pretty solid.

    In the login section, you would do something like:

    $_SESSION['_user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    $_SESSION['_remote_addr'] = $_SERVER['REMOTE_ADDR'];
    

    and then you can do a check in every request:

    function sessionIsOK ()
    {
        return ($_SESSION['_user_agent'] == $_SERVER['HTTP_USER_AGENT'] &&
            $_SESSION['_remote_addr'] == $_SERVER['REMOTE_ADDR']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画