Reputation: 140
So what is happening is I have a content editable DIV that i would like to be able to put code into and then hit save! I can do this with normal text and it saves fine, but when trying to save code it saves it as < ;img> ;
instead of <img>
Here is the code I am using to save the text to a file:
<?php
$news = $_POST['data'];
$myfile = fopen("../News/newspagedata.php", "w") or die("Unable to open file!");
fwrite($myfile, $news);
fclose($myfile);
?>
Any Help would be greatly appreciated!
Upvotes: 2
Views: 728
Reputation: 20747
It looks like either your Javascript or PHP is converting special characters into HTML entities so you need to do this:
$news = html_entity_decode($_POST['data']);
Please note that this leaves you 100% vulnerable to things such as this:
<script>
var i = 0;
while(i < 1){
// execute some code inifinitely
}
</script>
Upvotes: 2