Take the 2-minute tour ×

I am trying to make a simple script, but when I try to include the config file, it wont load. Here is my code-

$config = include("http://MyWebSite/config.php");
$mysql = mysql_connect($host, $user, $pass);
if (!$mysql) { die(mysql_error()); }
$data = mysql_select_db($database);
if (!$data) { die(mysql_error()); }
share|improve this question
I'm pretty sure you didn't mean to load "config.php" via HTTP. Try simply include("config.php") assuming it's in the same directory as the script. –  Eli Aug 29 '12 at 22:44
remove '$config = ' as well –  K'shin Aug 29 '12 at 22:44
If you use require instead of include, you don't have to guess whether or not your file is loaded. –  Arjan Aug 29 '12 at 22:47

4 Answers 4

up vote 5 down vote accepted

Try this:


Also, don't assign it to a variable. You simply want to include the file in the script.

share|improve this answer

1) include doesn't return anything 2) include whole url must be enabled by server

share|improve this answer
1) See Example #4 + #5 and paragraph above. –  ccKep Aug 29 '12 at 22:56

you should try like that


Because in normal server setting you are not allowed directly include files remotely.

share|improve this answer
@Basic: include has return values, see Example #4 + #5 and the paragraph above. –  ccKep Aug 29 '12 at 22:58
@ccKep I stand corrected and un -1 –  Basic Aug 29 '12 at 23:00

You need to make sure the path to the file is correct. The following code will look for config.php in the same directory as the script that you are running:


If that does not work you can look at the error logs or turn on error reporting with the following code:

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);

The error message should now show you where it is looking for the file. The error will look something like the following:

Warning: include() [function.include]: Failed opening 'config.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /path/to/your/script.php on line 4

The above message states that it could not find config.php at any of the following locations:

share|improve this answer

Your Answer


