I want to let members use html for a blog posting but want it secure for server as well as for visitors to blog.
I also am going to allow images in html. And I know it can be dangerous but I know there must be a way to make it safe.
I am also going to allow links in their html.
What they submit will not go into database but will be added to a txt file before being approved. After approved the txt file will be converted to a php file.
Anyways here is what you can add to if you can help make it safer.
function cleantext($str,$strlang=false) {
$str = rtrim($str);
// remove all harmful tags
$stripsearch = array("'<head[^>]*?>.*?</head>'si", // Strip out javascript
"'<!DOCTYPE[^>]*?>'si", // Strip out doctype
"'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<iframe[^>]*?>.*?</iframe>'si", // Strip out iframes
"'<iframe[^>]*?>'si", // Strip out iframes
"'<bgsound[^>]*?>'si", // Strip out iframes
"'<meta[^>]*?>'si", // Strip out meta tags
"'<form[^>]*?>.*?</form>'si", // Strip out forms
"'<object[^>]*?>.*?</object>'si", // Strip out objects
"'<embed[^>]*?>.*?</embed>'si", // Strip out embeds
"'<applet[^>]*?>.*?</applet>'si", // Strip out applets
"'</?body[^>]*?>'i", // Strip out body tags
"'</?html>'i", // Strip out html tag
);
$stripreplace = "";
$returnstr = preg_replace($stripsearch,$stripreplace,$str);
$changearr = array("\r"=>"\n",
"\r\n"=>"\n",
"\n\n\n" => "\n\n",
" "=>" ",
"<?"=>"<?",
"#exec"=>"itriedtohackthis",
"<meta"=>"<meta",
"<script"=>"<script",
"<iframe"=>"<iframe",
"<form"=>"<form",
"<object"=>"<object",
"<embed"=>"<embed",
"javascript:"=>"",
"onclick"=>"",
"ondblclick"=>"",
"onmousedown"=>"",
"onmouseup"=>"",
"onmouseover"=>"",
"onmousemove"=>"",
"onmouseout"=>"",
"onkeypress"=>"",
"onkeydown"=>"",
"onkeyup"=>""
);
$returnstr = strtr($returnstr,$changearr);
return $returnstr;
}