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!
1 Answer 1
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>
answered Feb 17, 2015 at 21:22
MonkeyZeus
20.8k5 gold badges41 silver badges83 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Jake Wilson
This is the correct answer. Ignore the people who are too dense to understand the question.
Mark Shaw
Upon doing this the file will no longer save?
Mark Shaw
Nevermind! This does work correctly, I forgot a ' when i retyped it! Thanks a lot!
MonkeyZeus
@MarkShaw glad to hear you got it working! You had me completely stumped as to why it stopped saving the file lol. Please heed my warning about the javascript injection though
Mark Shaw
Yes, i do understand your warning, this is all behind a login system though so unless that is broken into we should not have any issues! Thanks a lot!
|
default
"<img>"instead of""as per stackoverflow.com/revisions/28571145/1