开发者

PHP: Global variable for all pages

开发者 https://www.devze.com 2023-04-13 01:41 出处:网络
I need a constant that can be called from every php page. So, for example, I declare this constant somewhere, $APP_VERSION = \"5.5\".

I need a constant that can be called from every php page. So, for example, I declare this constant somewhere, $APP_VERSION = "5.5".

Then I would like to call this variable from any pages. how开发者_Python百科 to do this?


define('APP_VERSION', '5.5');

You can put that in the file that would be included into your pages. I'n that way you'd access it by APP_VERSION

echo APP_VERSION; //outputs 5.5


You can define constants using define:

define('APP_VERSION', '5.5');

Then, in other files:

echo APP_VERSION; // outputs '5.5'

http://php.net/manual/en/function.define.php


You could define a file (for example costant.php) which will contains all your constants and then you have to use include to be able to retrieve them in every script.

0

精彩评论

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

关注公众号