开发者

Storing a boolean value on the server

WordPress has this thing that examines whether it has been set up (installed) on the server and if it's not, it takes the visitor to a "install" page. I need to have something like that in a system I'm building.

I need to store a boolean value on the server.

What would开发者_JAVA技巧 be the most elegant / lightweight approach?


You could create a semaphore, where you just create an empty file, and then you just check if the file exists as your TRUE value.


Most of the packages that require installation or configuration have different ways. Some can check if a file exists then return true or false, write to a database, or have a configuration file included in all its scripts. Most go with the if(file_exists) method.

EDIT : Dabr has a config_bla.php file (with all the needed constants defined in the file) which should be renamed to config.php after installation.


This should do it:

function was_here_before()
{
    $file="/some/writable/file.txt";
    if (file_exists($file))
        return true;
    else
    {
        touch($file)
        return false;
    }
}

There are many ways however, YMMV.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜