dongyanhu5628 2017-01-18 17:42
浏览 44
已采纳

在会话之外的PHP中存储变量

In PHP, is there a way to store variables that persist between sessions and even different users accessing the page - that does not use a database, and is fast?

I am creating a marketing a/b split test script.

I wish to store a variable called $Pagecount - that is incremented each time anyone lands on my webpage - and the content shown is dependent on what the variable is.

I am not using MySQL or cookies for this.

  • 写回答

1条回答 默认 最新

  • duanchun6148 2017-01-18 17:51
    关注

    While a "text file" will work given appropriate filesystem write permissions, if such is allowed there are also other options that may be available. The availability depends on precise PHP build / configuration, as local filesystem access has already been assumed as a premise.

    • Use "sqlite". SQLite is an in-process embedded database that does not require a separate install like MySQL. A benefit SQLite is that it a relational database with a clear (SQL) API.

    • Use "*dbm" (eg. ndbm) which represents a class of in-process key value stores. These *DBM databases provide an API for very fast key-value access even though they lack SQL features.

    An advantage of using a database is it removes the need to care about an on-disk format (eg. will it be a single value in a file? an INI file? a JSON document?): the actual problem of storing information can be focused on.

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

报告相同问题?

悬赏问题

  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面