Re: Problem with variables
[email protected] (Jim Giner)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On 6/25/2013 5:46 PM, Fernando A wrote: > Hello, > > I am working with php and codeigniter, but I have not yet experienced. > I need create a variable that is available throughout system. > This variable contains the number of company and can change. > as I can handle this? > > Thank you, very much! > > Ferd > One way would be to create a file like this: <? // company_info.php $_SESSION['company_name'] = "My Company"; $_SESSION['company_addr1'] = "1 Main St."; etc. etc. etc. Then - in your startup script (or in every script), use an include statement: <?php session_start(); include($path_to_includes."/company_info.php"); Now you will have those SESSION vars available for the entire session, basically until you close your browser. You can also use the php.ini auto-prepend setting, which automatically does this for you, altho the vars would not be session vars, since the prepend-ed file happens before your script issues the session_start (I think).