php - How do I block HTML in my form input? -
so, have basic little script takes input html form, processes php , writes text file in form of css. i've got jerkwad trying drop tables on server (there no sql i'd keep people trying none less) here code have far, can me block potentially bad input via htmlentities or else?
the html form
<html><body> <h4>codes form</h4> <form action="codes.php" method="post"> username: <input name="username" type="text" /> usercode: <input name="usercode" type="text" /> <input type="submit" value="post it!" /> </form> </body></html> the php
<html><body> <?php $friendcode = $_post['usercode']; $username = $_post['username']; echo "you have recorded following information on server ". $username . " " . $usercode . ".<br />"; echo "thanks contributing!"; $output = ".author[href\$=\"$username\"]:after { \n" ."content: \" ($usercode)\" !important\n" ."}"; } $fp = fopen('file.txt', 'a'); fwrite($fp, $output); fwrite($fp, "\n"); fclose($fp); ?> </body></html>
whenever include data entered user in html code, idea first encode data, passing htmlspecialchars().
think of decontamination chamber. ensure of html special chacters, such "<" , ">" (deadly viruses) escaped (killed) , won't show in page "real" html tags (won't make webpage sick).
similarly, must encode user input when including in sql queries. function use purpose varies depending on database using. because of dynamic nature of php, if including numeric value in sql query, must first check make sure variable contains number using functions such is_numeric() , ctype_digit().
Comments
Post a Comment