1

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")?

2
  • How are you going to work with the variable once you get access to it? It could still contain malicious code. What's your end goal? Commented May 16, 2012 at 0:11
  • What's wrong with not validating user input? Commented May 16, 2012 at 0:12

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Having a look at this answer on another question may send you in the right direction : https://stackoverflow.com/a/1858294/303657

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.