Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically load a config.php file for all pages before anything else

Does anyone know how to set up something where a specific file can be loaded automatically for all pages before anything else?

For example if I have a config.php file and I want this file to be loaded anytime anyone visits a page on my website.

In here I would have some configuration info that is required to load prior to anything else.

I don't want to do any includes on another php file for this I just want this to be loaded every time automatically before anything else. Basically a universal include.

like image 340
Yeak Avatar asked Feb 14 '13 21:02

Yeak


People also ask

Where do I put config php?

The wp-config. php file is usually located in the root folder of your website with other folders like /wp-content/. Once you have downloaded the wp-config. php file, you can make the appropriate changes then re-upload it to your web server.

What is a WP-config php file?

The wp-config. php file provides the base configuration details for your WordPress website. The wp-config. php file is a WordPress core file that contains the necessary information to make your WordPress website operate, including: Your WordPress database MySQL connection settings.

How does config php work?

The wp-config. php file is a configuration file created during the WordPress installation process. It stores database information such as the database name, username, password, and host. In addition to establishing a connection between your WordPress site and its database, WordPress also uses the wp-config.

How do I access WP-config php without FTP?

WordPress configuration file (wp-config. php) is located in your WordPress installation directory. You can edit your blog wp-config. php file through WordPress hosting cPanel » File Manager and find the file called wp-config.


1 Answers

You want to use auto_prepend_file. Set this directive in your php.ini or .htaccess file to the path to your config.php file and any PHP file accessed will automatically have the contents of the config file prepended to it.

For .htaccess:

php_value auto_prepend_file /full/path/to/file/config.php

Keep in mind this ONLY will work on a server where PHP is run as an Apache module. If PHP is run as a CGI you need to add edit it in your php.ini file or put it inside a .user.ini file just without the php_value part.

In Nginx you could add this line to server configuration inside location ~ \.php$

fastcgi_param PHP_VALUE "auto_prepend_file=/full/path/to/file/config.php";
like image 103
cryptic ツ Avatar answered Nov 20 '22 23:11

cryptic ツ