Hi I have a simple problem. I want to set value of a variable and use it in several php scripts in my site to access it. Can you please advise me the best way to go. thanks for your time.
Will all scripts be using the same login? Maybe a session variable would be the better way to go in that case.
Hi This variable is carriage charge and is constant and may not change from one year to next. The scripts do use the same database and several tables. I am sorry if I am not too clear as I am fairly new to php. So, just to sum up, I use this carriage charge on many pages and instead of going and manually changing them in 10 or so different places I thought it might be handy if I could write it once and refer to it in all occasions. thx
OK. You're not looking for a super global. Your best bet (IMO) would be to create a single php page called global_variables or something similar, define them in that page, and include the page in all other pages via the header or connect file.
Hi Altari Many thanks for your advice. Could you please tell me the commands I need to look up to learn more about using variables using "header" and "connect file" or do you mean using the command "include"? Thanks jacka
Or just use the common method of using a config file, like: <?php $specialvariable = 'special value'; ?> PHP: And include it in every file by using: <?php include_once('path/to/config.php'); /* rest of the code goes here */ ?> PHP:
Hi Thanks for your comments. Does this have to be named config or can I call it any name I like. What I am really asking is, is there any thing significant about the config file? thx jacka
There's nothing significant. It's a good practice to make it meaningful, though. If you have a bunch of different scripts running, calling it "config.php" will be more than a little ambiguous, so make sure the name means something to you. Good luck. =)