开发者

Control parts of code through external on off config file?

I want to have a config file that basically says something like (Account: on/off), where an admin can choose on or off. And then, in my main script, i want a bunch of if else statements 开发者_开发知识库that says if its on, do this, if off, do this.

Any suggestions?


config.php:

<?php
$account = 'off';

main_script.php:

<?php
include('config.php');

if ($account == 'on') {
    //do this
} else {
    //do something else
}


Config files usually define global constants available everywhere in your code and often seen in the variable $GLOBALS['config']. Config files are normal PHP files that get included using include() or better include_once() at the very top of your applications main file.

include_once('config.php');
if ($GLOBALS['config']['admin']) doThis();
else doThat();

http://php.net/manual/de/reserved.variables.globals.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜