I don't know how to search for it, so I'm asking you here.
Situation is the following:
Got a vServer with root. Apache, PHP5, MySQL installed and running.
Now I have an index.php
where I want to include 'config.php';
. Simple thing!
In the config.php
I have a variable like $url = 'http://xxxxxxx';
, but I cannot access it in the index.php
. There's just an empty Array, when I print_r(parse_url($url));
it.
The curious thing is, when I'm connected with ssh to the server and run php index.php
, the output is the whole array as expected.
Do you have any idea?!
Have you tried to include your config.php with absolute path, eg. include('/var/www/config.php');
The best strategy for a config file would be having it written in the following format:
<?php
return array(
'url' => 'http://xxxxxxx',
...
);
Then in your index.php
you can do $config = require('wherever/it/is/config.php')
and access your parameters like $config['url']
. Otherwise you would probably have to use globals which is almost never a good practice.
Damn, I'm so stupid.
I had something like:
config.php
foreach {
if(true){
something;
return false;
}
}
$url = ...;
I just wanted to stop the foreach
if it was successful. Maybe worked too good..
But I don't understand, why it hadn't any errors when php
ing it in the terminal..
Thank you guys!