News:

The "Support Requests" forum is now viewable by guests.

Main Menu

Creating A Global Variable

Started by sixthcrusifix, January 11, 2006, 10:24:41 PM

Previous topic - Next topic

sixthcrusifix

Is there anyway I can create a variable or a value I can access with something like $_Blah['blahblah']

Because I want to include a rather lengthy peice of code to every page and since it needs to go on every page I thought it would be easier to have it in a special variable.

Original had set it in a PHP page and then included the page to use the variable but Idon't wanna have to include a page on every page because I'm not sure if that's good to do.

I really want to make a custom $_ Variable so I can change it's value (like a function).
Visite me website at http://www.sixthcrusifix.com

GP™

To be honest, I have never heard of such a feature in php, other than editing the php config file, which is not a option for our users.
so i'm quite intrested to see if there is such a feature..

L8r,
Gordon

webzone (archived)

You can't set variables that will be available in all your scripts. The only way is to set those in a file and then use include(), require() or auto_prepend_file (the latter is in the php config file).

Including a file takes a bit more time to process but not by much. For instance, I'm using Wordpress on a site that I manage. Wordpress includes at least a dozen files when any page is requested, but my page still appears pretty quickly and this does not seem to cause too much problems.

You can improve performance by using constants instead of variables, but you will not be able to change their value. A great advantage is that constants are automatically global, so you can use them inside any function without having to use the "global" keyword.

If you choose to use include(), keep in mind that you must give the path of the desired script on the local system (ie. use /fpgs/... instead of http://...).

sixthcrusifix

Quote from: webzone on January 11, 2006, 11:56:29 PM
You can't set variables that will be available in all your scripts. The only way is to set those in a file and then use include(), require() or auto_prepend_file (the latter is in the php config file).

Including a file takes a bit more time to process but not by much. For instance, I'm using Wordpress on a site that I manage. Wordpress includes at least a dozen files when any page is requested, but my page still appears pretty quickly and this does not seem to cause too much problems.

You can improve performance by using constants instead of variables, but you will not be able to change their value. A great advantage is that constants are automatically global, so you can use them inside any function without having to use the "global" keyword.

If you choose to use include(), keep in mind that you must give the path of the desired script on the local system (ie. use /fpgs/... instead of http://...).

yes I use include a lot for a Style that I have on my site (PHP STyle -long story) I wil lprobably just make the variables in a smalle rpage  and include them. One good thing I thought of was setting Functions to variables so you can use them in echos!
Visite me website at http://www.sixthcrusifix.com