onlyican Posted December 28, 2006 Share Posted December 28, 2006 Hey peopleMerry Christmas, and a happy new year to ya allNowI have a function, which secures against SQL Injection.[code]<?phpfunction MakeSafe($str, $lower = false){ if($lower == true){ $str = strtolower($str); } $str = eregi_replace("%", "", $str); $str = eregi_replace("--","",$str); $str = stripslashes($str); $str = strip_tags($str); $str = htmlspecialchars($str); $str = trim($str); $str = mysql_real_escape_string($str); return $str;}?>[/code]I used to enter some code like"It's just a test"And it would come out likeIt\\\'s just a testSo I added StripslashesNOWon my Local machineI added the following[quote]It's Just a testDoes it work[/quote]In my MySQL TableIt readsIts Just a TestnrDoes it workThe Stripslashes has removed ALL slashes, and the mysql_real_escape_string has not added the main ones in (it's needs one)BUTOn My Server, It works as it should, having \n\r and it\'sSo I am guessing it is a setting thingAny ideas? Link to comment https://forums.phpfreaks.com/topic/32041-solved-help-with-my-function/ Share on other sites More sharing options...
alpine Posted December 28, 2006 Share Posted December 28, 2006 You should check if get_magic_quotes is on or not before running stripslashesexample:[code]<?phpfunction MakeSafe($str, $lower = false){if(get_magic_quotes_gpc()){$str = stripslashes($str);}if($lower == true){ $str = strtolower($str);}$str = str_replace(array("%","--"),"", htmlspecialchars(strip_tags(trim($str)), ENT_QUOTES));return mysql_real_escape_string($str);}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32041-solved-help-with-my-function/#findComment-148714 Share on other sites More sharing options...
onlyican Posted December 28, 2006 Author Share Posted December 28, 2006 Thats the differnce, its on one, not the other.Cheers for that. Link to comment https://forums.phpfreaks.com/topic/32041-solved-help-with-my-function/#findComment-148730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.