duanhan9479 2012-07-06 20:22
浏览 34
已采纳

PHP会话与Cookie [重复]

Possible Duplicate:
Cookie VS Session
PHP: How do Cookies and Sessions work?

I'm trying to learn PHP. I have a project website where numbers are constantly being generated, and changed and stored in javascript variables. There is very little php involved except in storing these variables to a database when the user hits the "store to database" button. Today I was using the site, navigated to another website and went back and all my data was gone as i had not stored it to the database first. I would like to save that data so it repopulates if I leave the page. what would be the best method of doing this? php sessions, cookies, or javascript cookies? please advise, thanks in advance!

  • 写回答

5条回答 默认 最新

  • doukuiqian9911 2012-07-06 20:27
    关注

    php sessions, cookies, or javascript cookies?

    There is either a session or cookie so there are two things not three.

    Now a session is also a cookie but is saved on server unlike simple JS cookie which is saved in user's machine.

    I would like to save that data so it repopulates if I leave the page

    If it is sensitive information, always use database to store it and if it is not sensitive data:

    • Use cookies or localStorage but it can be deleted by user
    • Use session which can't be deleted by a user but will expire based on php.ini settings

    On the other hand, to save it permanently, use the database instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元