I am trying to prevent xss injection. So before I submit a form, a javascript function is called
function validatefield(id) {
var description = document.getElementById(id).value;
description = description.replace(/[\"\'][\s]*javascript:(.*)[\"\']/gi, "");
description = description.replace(/script(.*)/gi, "");
description = description.replace(/eval\((.*)\)/gi, "");
document.getElementById(id).value=description;
}
I am wonderng if there's a way to do the same in php before inserting into the mysql? if they get around of the validatefield function.
Thanks
onclickattribute. The right (and much simpler!) way to go is to wrap your user submitted data inhtmlspecialchars()just before outputting in in any html context.