doujia4759 2017-02-07 20:07
浏览 44

PHP如何知道哪个SESSION变量与设置它的每个浏览器一起使用?

I understand that SESSION variables are stored in PHP.
But, if I close my browser, then go back to the page, how does PHP know that previously set session belongs with my browser?
Ip address?

If it uses an IP, couldn't someone just fake an IP address and login to other users accounts because that is how PHP associates the session with the browser?

  • 写回答

1条回答 默认 最新

  • dsghpgmay31938863 2017-02-07 20:11
    关注

    From the docs (emphasis mine):

    Sessions are a simple way to store data for individual users against a unique session ID. This can be used to persist state information between page requests. Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data. The absence of an ID or session cookie lets PHP know to create a new session, and generate a new session ID.

    When a new session is started PHP generates a random string. This ID is then sent back to the browser as a cookie value. Subsequent requests pass this cookie back to the server so it can be looked up and know it's the same user coming back. The random session ID makes it hard for others to guess and gain access to another person's session.

    In the most recent version of PHP you can set the length of the session ID if you're concerned it's easy to guess. But statistically the defaults for session ID generation are not a concern for most websites.

    The session.name configuration determines the cookie name in the browser. By default it is PHPSESSID.

    评论

报告相同问题?

悬赏问题

  • ¥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,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?