Discussion:
Problem with variables
Fernando A
2013-06-25 21:46:28 UTC
Permalink
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
Jim Giner
2013-06-25 22:15:38 UTC
Permalink
Post by Fernando A
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).
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tamara Temple
2013-06-29 01:16:27 UTC
Permalink
Post by Fernando A
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?
Hi, Fernando, welcome. I'm just a little unsure what you mean by "number
of company" -- is this a count, as in 10 companies, or is it a phone
number, or is it something else?

Jim's reply is workable -- storing session values is quite useful, but
sessions are tied to a specific browser client/ip, and I'm not sure
that's what you want/need here.

If you are looking for setting a global variable that will be available
everywhere in your application, you can use $GLOBALS, or set it from the
very top level context of the application. Given you're using
CodeIgniter, which sadly I am not versed in, you may need to set it with
$GLOBALS:

$GLOBALS['my_var'] = 10; // whatever you need to do here

When you say it changes, how and when exactly does it change?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...