Jump to content

[SOLVED] how to properly use a config.php file?


xiao

Recommended Posts

I currently use something like this:

 

config.php

<?php

/**
* @author Sander Quirynen
* @copyright IPCS.be
*/

# Language

//ID of...
$instT = "1";

 

index.php

...
require ("config.php");
...

 

But I get an error on my index.php saying

Notice: Undefined variable: instT in C:\xampp\htdocs\pcconfig\index.php on line 128

I include the file on line 8...

 

Link to comment
Share on other sites

Fixed it.

I was trying to use those variables inside functions -_-'

Is there maybe a better way besides using 'global $...' everytime I need sth in a function?

I don't really want to use session variables either since I already use like 30 of those.

Link to comment
Share on other sites

IMO you should NOT use variables as configuration settings - instead use constants; after all configuration settings are constants...

 

My config files take the guise of...

 

<?php

define ( 'SETTING1' , 'setting1value'); // comment on constants meaning
?>

 

the beauty of using constants over variables lies in the memory use involved - constants are more efficient.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.