Jump to content

[SOLVED] The code behind configuration files...


pugboy

Recommended Posts

First question--

 

In almost EVERY forum and CMS package, they have a web based installer to create the configuration file for you (vBulletin might not, but I can't remember).

 

How exactly do they do this? I was going to recreate this by using str_replace and finding a unique string in the file, but most of the time the fields are actually blank.

 

My file is just a class:

<?php
//Setting file...
//No need to edit this unless you are manually installing

class Settings {
//General Website Stuff...
var $sitename = '<HIDDEN FOR SECURITY REASONS>'; //Site title... Shown in header of website
var $longTitle = '<HIDDEN>'; //Long title. Shown in title bar
var $siteslogan = '';

var $offline = '0'; //Is the site offline? Usually 0 (No)
var $offline_message = '$sitename is currently down for maintenance.<br/>Please check again soon!';

//Database stuff...
var $db_type = 'mysql'; //Possible values: mysql

var $db_prefix = 'wcms_'; //Defaults to wcms_. Change if you want to install more than one script on one database (for those with smaller hosting packages)

var $db_host = 'localhost'; //Database host... Usually localhost on the hosts that don't mega-oversell. You know who I am talking about.

var $db_name = ''; //Database name... Get this from your webhost

var $db_user = ''; //Database username. Default MySQL username is root with no password. Again, get this from your host.
var $db_pass = ''; //Database password. Don't worry, no one can see this unless they have FTP access to this file

}
?>

you could use a cached ini file for easy modification, a database config (also cached), or you could do a preg_replace with a pattern like

 

public \$sitename = '([^']*?)';

 

note I used public instead of var because php 5 has been out for a long time :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.