开发者

PHP environment variables? Storing data without databases

Is there a way to store a value, without writing it to a file, or storing it in a database. I think its called environment variables.

So lets say I received a value of true from a form checkbox, and that value enables and disables a certain functiona开发者_运维百科lity in my site. I submitted the change, and I'm an admin, no one else has access to this form. However my answer to the checkbox true or false needs to effect all future sessions based on how I last set it.

Let me make a more concise example.... From an administrative dashboard, i want to enable and disable pages, (put them into maintenance mode). I don't really wanna store this value in a database, and I'm too lazy to write it to a file. So there is an if statment at the beginning of each of the pages,

if($iamdisabled)
{
    die(sorry, you can't access this page right now");
} 

can i store that variable somewhere that will be save between different people and different sessions, without a database?


If you want some persistence, database or file storage is the way to do things. Any other data will be lost if:

  • The server application is stopped, or if
  • The server machine is rebooted.

Further, if your website is hosted on multiple servers, storing options in the database will be the easiest way to do things.


Store in some sort of global memory cache, such as memcache or SysV shared memory.


Not without writing it somewhere. You have the following options:

1- Write it to a file (or touch a file and check for its existence)

2- Manually update a CONFIG file with a GLOBAL variable

3- Use a database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜