Asked  2 Years ago    Answers:  5   Viewed   83 times

I want to create a config file for my PHP project, but I'm not sure what the best way to do this is.

I have 3 ideas so far.

1-Use Variable

$config['hostname'] = "localhost";
$config['dbuser'] = "dbuser";
$config['dbpassword'] = "dbpassword";
$config['dbname'] = "dbname";
$config['sitetitle'] = "sitetitle";

2-Use Const

define('DB_NAME', 'test');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('TITLE', 'sitetitle');

3-Use Database

I will be using the config in classes so I'm not sure which way would be the best or if there is a better way.



One simple but elegant way is to create a config.php file (or whatever you call it) that just returns an array:


return array(
    'host' => 'localhost',
    'username' => 'root',

And then:

$configs = include('config.php');
Monday, September 26, 2022

Same problem with 000webhost and bluehost and ProISP, any PHP process running for more than 120 seconds will be terminated, regardless of settings, to prevent the server from overloading, and you must ask a engineer (that actually know what the problem is) for your account/script to get an exemption from this security feature (good luck. Only ProISP actually gave me an exemption for this, for 1 specific php script..) - or you could buy a VPS (ex, ) , or use a webhost that doesn't have this limitation (like ) , or use a webhost that might be willing to give you an exemption (like )

GoDaddy support staff are retarded. why? header( "refresh:30; url=" ); this will make YOUR BROWSER redirect and has nothing to do with php execution time, and they were unable to find the real cause of the problem, and the real problem has nothing to do with your cpu usage.

Friday, November 4, 2022

It's just a warning to show that there is no password for the default user root. If you want to set password for root:

  1. Open phpmyadmin interface
  2. Click "Users" tab
  3. Select user "root"
  4. Edit Privileges
  5. Change password
Friday, September 23, 2022

There is also PCLZip, a pure PHP alternative to ZipArchive that can be found at

Thursday, August 25, 2022

You can either use absolute path which could be /Myproject/Config/config.php or reset your directory by navigating in upper level folder and then going to your require file ../../Config/config.php

So you can manage to include with


As stated in include documentation

If a path is defined — whether absolute (starting with a drive letter or on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.


Let's analyze include path. We are actually in Modules/Home/ folder. te reach root level and can get inside Config folder we need to go two level upper, and we can do this by doing ../ for each level, so in our case ../../. Now that we are in root directory we can navigate through Config/ and get our desired file config.php. Now mixing all toghter will will have ../../Config/config.php.

Monday, September 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages