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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.