Skip to content Skip to sidebar Skip to footer

Get Php Variable Value Via Ajax With Variable Name As Parameter

I realise similar questions have come up a few times, but I can't seem to find one that will help with what I am trying to do. We have a config.php file which is basically a list

Solution 1:

Maybe the better option will be to set config variables inside an array:

$CFG = array(
    'OUR_EMAIL_ADDRESS' => 'test@test.com',
    'OUR_WEBSITE' => 'www.test.com'
);

And pick up them with:

$var_name = $_GET['name'];
echoisset($CFG[$var_name]) ? $CFG[$var_name] : "";

Otherwise, it might be a real security problem of your script.

Solution 2:

Yes, it is possible via variable variables:

echo $$var_name;

However, this is unwise since you are taking user input and possibly the user can get values of internal variables that are supposed to be hidden.

Solution 3:

create a dictionary with all your config variables and use it to look up a variable by name

Post a Comment for "Get Php Variable Value Via Ajax With Variable Name As Parameter"