Bisa Posted October 22, 2008 Share Posted October 22, 2008 I've been working on a form and it is functional at the moment, now it's time to secure it from injections and at the same time I figured I'd convert å, ä and ö so that they would be correctly rendered by browsers all around. My function looks like this and I would appreciate any pointers regarding security so far as well as perhaps be able to spot why the åäö converting prevents anything else of my script to be run when I load the page //Function to prevents SQL Injection and convert åäö function secureFormInput($formdata) { $formdata = ereg_replace("[\'\")(;|`,<>]", "", $formdata); $formdata = trim($formdata); $formdata = stripslashes($formdata); $replace = array("å", "ä", "ö", "Å", "Ä", "Ö"; $with = array("å", "ä", "ö", "Å", "Ä", "Ö"); $formdata = str_replace($replace, $with, $formdata); return $formdata; } Edit, oops, I posted this in the wrong section (reported to mod) Link to comment https://forums.phpfreaks.com/topic/129540-solved-function-to-prevent-sql-injection-and-converting-%C3%A5%C3%A4%C3%B6-review-this-one-plea/ Share on other sites More sharing options...
luca200 Posted October 22, 2008 Share Posted October 22, 2008 First of all the åäö converting prevents anything else of my script to be run when I load the page I'm sorry but my English is too bad to understand what you mean with this Anyway, I have many objections to your code, and the first is a simple question: why not using mysql_real_escape_string() (or similar functions for other db's)? I do not agree about altering what the user posted, so I will not change quotes to backticks. Neither will I change non-latin characters to html entities: what if tomorrow you decide to use those data for other than a web page? Another thing you should avoid is using stripslashes() when you're not sure that magic_quotes_gpc is on. Regards Link to comment https://forums.phpfreaks.com/topic/129540-solved-function-to-prevent-sql-injection-and-converting-%C3%A5%C3%A4%C3%B6-review-this-one-plea/#findComment-671697 Share on other sites More sharing options...
Bisa Posted October 22, 2008 Author Share Posted October 22, 2008 First of all the åäö converting prevents anything else of my script to be run when I load the page I'm sorry but my English is too bad to understand what you mean with this Anyway, I have many objections to your code, and the first is a simple question: why not using mysql_real_escape_string() (or similar functions for other db's)? I do not agree about altering what the user posted, so I will not change quotes to backticks. Neither will I change non-latin characters to html entities: what if tomorrow you decide to use those data for other than a web page? Another thing you should avoid is using stripslashes() when you're not sure that magic_quotes_gpc is on. Regards Thnx for the feedback =) 1. about mysql_real_escape_string(), I tried using that but since I'm not putting stuff into a db at the moment I left out the link_identifier and that stopped the rest of the script to be executed so I simply removed the mysql_real_escape_string() for now. 2. html entities - well, I am unable to have my browser show å, ä and ö so I figured if I converted them I would solve that problem but yea, you are right I am planning on sending the user input via email and then it's not optimal to show html entities but instead the real characters. Anyone got some code examples of how could put this to good use? Link to comment https://forums.phpfreaks.com/topic/129540-solved-function-to-prevent-sql-injection-and-converting-%C3%A5%C3%A4%C3%B6-review-this-one-plea/#findComment-671704 Share on other sites More sharing options...
Bisa Posted October 22, 2008 Author Share Posted October 22, 2008 never mind, I solved the å ä and ö problem by changing the charset to iso-8859-1, I'll google the security stuff - thnx for ur time ppl Link to comment https://forums.phpfreaks.com/topic/129540-solved-function-to-prevent-sql-injection-and-converting-%C3%A5%C3%A4%C3%B6-review-this-one-plea/#findComment-671763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.