dpa84373 2013-04-12 22:28
浏览 41
已采纳

PHP cookie和成员安全性

I've created a forum which uses a PHP session when logged in to determine the user id, and cookies for log-term login.

I suppose I have two questions:

  1. Is this the best/securest method?
  2. Cookies can be added manually via the address bar with javascript, which is a huge security risk. Is there any way around this?

Thanks!

  • 写回答

1条回答 默认 最新

  • duan35557593 2013-04-12 22:30
    关注

    First, make sure you are using https and not http. This will keep your traffic from getting sniffed and exploited.

    Secondly, generate as random a value as possible to use as a token in the cookie. This is how many of the big sites do their user tracking. Have a map of token to user on the server side that tracks the identities. Remember: Anything that comes from the client is untrusted and could be tampered with.

    Third, use an HMAC to make tampering much more difficult. You don't want users being able to brute force other tokens.

    EDIT:

    You may find these other SO questions/answers helpful as you build this system:

    1. Long details about creating and using tokens (doesn't necessarily have to be a REST service to be applicable): REST Web Service authentication token implementation

    2. Creating good tokens (don't use microtime): Is using microtime() to generate password-reset tokens bad practice

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法