• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Validate/Secure form input that will later be displayed

Drakkon

Diamond Member
Trying to secure a script thats used to post data to a DB thats later shown via HTML. Trying to avoid script attacks I was using htmlspecialchars and to avoid SQL injection using sprintf and real_escape_string. Is this going overkill? is there something easier?

//if there is a post make sure it only contains the 2 possible options
if(isset($_POST) && isset($_POST['id']) && isset($_POST['post']) &&count($_POST)==2) {
//make sure length of post variables is not too long
if(strlen($_POST['id'])>2) die('Invalid id');
if(strlen($_POST['post'])>80) die('message too long');
//modify post variables to make sure they contain no malicious code
$post = htmlspecialchars(sprintf('%s',$db->real_escape_string($_POST['post'])), ENT_QUOTES);
$id = htmlspecialchars(sprintf('%s',$db->real_escape_string($_POST['id'])), ENT_QUOTES);
}
 
Anyone hear of the PHP class Inspekt? I started playing with it and seems to clean up data pretty well
 
Back
Top