Reputation: 3158
I'm creating a php application that allows the user to install different themes.
Each theme directory must be placed in the "themes" directory.
Each theme must have a file called theme_profile.php
which have theme specifications such as the name of theme and etc...
So this theme_profile.php has a bunch of variables wrapped inside an array called $theme, ($theme["title"]="My theme"
etc...)
Now I want my application index file to get these variables without simply 'including' the file (which is risky if malicious code is placed in this file).
Is there anything such as get_variables_from_file("file.php")
?
Upvotes: 1
Views: 105
Reputation: 1696
As mentioned in other answers, using PHP is not necessary in such cases. Actually it is better to use data files. (Like XML, JSON, etc.)
This is a sample JSON encoded file:
// first create the $theme array
$theme['title'] = '...';
$theme['...'] = '...';
// then json encode it
$themeJson = json_encode($theme);
// put it in a file
file_put_contents('theme_profile.json', $themeJson);
For loading purpose, simply use json_decode function.
You can also use PHP serialize the same way.
Upvotes: 0
Reputation: 1643
Having a look at this answer on another question may send you in the right direction : https://stackoverflow.com/a/1858294/303657
Upvotes: 0
Reputation: 1696
it is not necessary to use php file for this purpose. Simply create an XML or any other of data files types and parse them in your PHP code. This is much safer.
Upvotes: 4