0

I have two files, index.php and config.php. Config.php has a lot of variables, such as $CONF, $CONF, etc. How can I edit those variables from index.php?

For example, if someone hasn't used my script yet, then $CONF = 'no'. When they do use it, I want $CONF = 'yes'. How would I do that?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by darkagn
0

You have two choices. The easiest way is to set the $CONF array to global in the functions that use it. Like so:

function foo()
{
  global $CONF;
  // do something here with $CONF
}

function bar()
{
  global $CONF;
  // do something else here with $CONF
}

However, for this method to work you need to include one of the php files in the other. So from your description, index.php would need to include the config.php file. This may not be feasible though, which brings me to method two.

Instead of storing your config options in $CONF, you can store everything in the superglobal $_SESSION. This allows you to pass variables between pages like so:

// config.php
$_SESSION['sql_user'] = $CONF['sql_user'];

// index.php
if( isset( $_SESSION['sql_user'] ))
{
  $user = $_SESSION['sql_user'];
}
else
{
  $user = $me; // for example
}

Another way would be to pass by $_GET, but this is less secure as the variables are passed in the url of the page.

HTH,
d

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.