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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?