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 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计