
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 1.53 KB | hits: 13 | expires: Never
Best way to store html in a config file
<?php define('WAIT_MESSAGE', '<p>Please wait.. your download starts shortly</p>'); ?>
<?php
echo base64_decode(WAIT_MESSAGE);
?>
<?php
/*Function to check if magic_quotes is enabled.
(Stops double slashes happening)
*/
function check_magic_quotes($value){
if (get_magic_quotes_gpc()) {
return stripslashes($value);
} else {
return $value;
}
}
/*Form was posted,
You should also do a check to see if logged in and have rights to edit*/
if($_SERVER['REQUEST_METHOD']=='POST'){
//Check for magic quotes and then base64_encode the string.
$value = base64_encode(check_magic_quotes($_POST['configVal']));
/*Use heredoc to create the php line for the config & insert the
base64 encoded string into place*/
$config=<<<CONFIG
<?php define("WAIT_MESSAGE", '$value'); ?>
CONFIG;
file_put_contents('someConfig.php',$config);
}
//When you want to include the config
include('someConfig.php');
/*To echo out the config value: base64_decode it,
and then htmlentities encode it, to protect from XSS*/
echo 'This was included: '.htmlentities(base64_decode(WAIT_MESSAGE));
//Basic form with current value when someConfg.php has not been included
$config = file_get_contents('someConfig.php');
preg_match("#"WAIT_MESSAGE", '(.*?)'#",$config,$match);
?>
<form method="POST" action="">
<p>Config Value:<input type="text" name="configVal" value="<?php echo htmlentities(base64_decode($match[1]));?>" size="20"><input type="submit" value="Update"></p>
</form>