Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Best way to store html in a config file
  2. <?php define('WAIT_MESSAGE', '<p>Please wait.. your download starts shortly</p>'); ?>
  3.        
  4. <?php
  5.     echo base64_decode(WAIT_MESSAGE);
  6. ?>
  7.        
  8. <?php
  9. /*Function to check if magic_quotes is enabled.
  10.  (Stops double slashes happening)
  11. */
  12. function check_magic_quotes($value){
  13.     if (get_magic_quotes_gpc()) {
  14.         return stripslashes($value);
  15.     } else {
  16.         return $value;
  17.     }
  18. }
  19.  
  20. /*Form was posted,
  21. You should also do a check to see if logged in and have rights to edit*/
  22. if($_SERVER['REQUEST_METHOD']=='POST'){
  23.     //Check for magic quotes and then base64_encode the string.
  24.     $value = base64_encode(check_magic_quotes($_POST['configVal']));
  25.  
  26.     /*Use heredoc to create the php line for the config & insert the
  27.       base64 encoded string into place*/
  28. $config=<<<CONFIG
  29.     <?php define("WAIT_MESSAGE", '$value'); ?>
  30. CONFIG;
  31.  
  32.     file_put_contents('someConfig.php',$config);
  33. }
  34.  
  35.  
  36. //When you want to include the config
  37. include('someConfig.php');
  38.  
  39. /*To echo out the config value: base64_decode it,
  40.   and then htmlentities encode it, to protect from XSS*/
  41. echo 'This was included: '.htmlentities(base64_decode(WAIT_MESSAGE));
  42.  
  43.  
  44. //Basic form with current value when someConfg.php has not been included
  45. $config = file_get_contents('someConfig.php');
  46. preg_match("#"WAIT_MESSAGE", '(.*?)'#",$config,$match);
  47.  ?>
  48.  
  49. <form method="POST" action="">
  50.   <p>Config Value:<input type="text" name="configVal" value="<?php echo htmlentities(base64_decode($match[1]));?>" size="20"><input type="submit" value="Update"></p>
  51. </form>