Hi friends,
In my site, simply I want to save the configuration data, site details in the php file.
For an example, in vBulletin they are using config.php file to save all the general details.

    //  ****** DATABASE TYPE ******
    //  This is the type of the database server on which your vBulletin database will be located.
    //  Valid options are mysql and mysqli, for slave support add _slave.  Try to use mysqli if you are using PHP 5 and MySQL 4.1+
    // for slave options just append _slave to your preferred database type.
$config['Database']['dbtype'] = 'mysql';

    //  ****** DATABASE NAME ******
    //  This is the name of the database where your vBulletin will be located.
    //  This must be created by your webhost.
$config['Database']['dbname'] = 'test';

    //  ****** TABLE PREFIX ******
    //  Prefix that your vBulletin tables have in the database.
$config['Database']['tableprefix'] = '';

I want to store details such as Site Name, database connection and some other things.
How can I do it?

Recommended Answers

All 5 Replies

Member Avatar for diafol

Config files come in all shapes and sizes. You can have plain php files where you store data in constants or variables. Alternatively, you can store config data in an ini file. These are special format text files which can be read using parse_ini_file()

The scope and form pretty much depends upon the complexity of your site. You may find a simple include file with a few vars or constants sufficient for your needs. The config file needs to be simple enough typically with just assignments, so it can be used with ajax calls. When you start creating too many dependencies, simple ajax calls can become a nightmare. Also watch out for duplication - that's a killer.

If you're storing sensitive data like db passwords in your config file, remember to store it above the document root, so it can't be accessed outside your own scripts.

Thank you very much for your reply.
Can you explain more above this section please? How can I store that file above the document root.

If you're storing sensitive data like db passwords in your config file, remember to store it above the document root, so it can't be accessed outside your own scripts.

Member Avatar for diafol

Your document root is that folder which is accessible to the world (public), it is sometimes called "public_html" or "htdocs" or possibly other things (the "directory" where you usually place your index.html or index.php page), anyway, create a folder above this, and place your config file there if it contains sensitive data like passwords.

Thanks all

All means, diafol ;)

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.