Demonic Posted September 17, 2006 Share Posted September 17, 2006 [code]<?phpfunction no_injection($string){if(!htmlspecialchars($string)){$string = htmlspecialchars($string);}return $string;}?>[/code]would this work in any way? Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/ Share on other sites More sharing options...
wildteen88 Posted September 17, 2006 Share Posted September 17, 2006 This bit makes not sense:[code]if(!htmlspecialchars($string)){$string = htmlspecialchars($string);}[/code]How will PHP know you have ran htmlspecialchars? Also this bit of code [code=php:0]$string = htmlspecialchars($string);[/code] will never be run, as PHP will run htmlspecialchars on the string being passed to the function in this bit of code:[code=php:0]if(!htmlspecialchars($string)){[/code]. So yout function is abit of a waste. Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93491 Share on other sites More sharing options...
Demonic Posted September 17, 2006 Author Share Posted September 17, 2006 [code]<?phpfunction no_injection($string){$string = htmlspecialchars($string);return $string;}?>[/code]Keep it simple and short? Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93492 Share on other sites More sharing options...
onlyican Posted September 17, 2006 Share Posted September 17, 2006 For making things secure I do the following[code]<?phpfunction MakeSafe($str, $make_lower = false){if($make_lower){$str = strtolower($str);}$str = stripslashes($str);$str = trim($str);$str = strip_tags($str);$str = mysql_real_escape_string($str);return $str;}//This will make string safe, and lower case (for usernames ect)$username = MakeSafe($_POST["username"], 1);//This will make string safe, keeping case, (For names ect)$name = MakeSafe($_POST["name"]);[/code]Note that the 1 (or any value, true, a, lowecase) is what makes it lowercase Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93495 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 i don think htmlspecialchars can do all the strings called $strings as what you want i think they all gotto be set sepratly.good luck.[code]<?php$name="redarrow";function name($name){$name = htmlspecialchars($name); )function name($name);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93496 Share on other sites More sharing options...
Demonic Posted September 17, 2006 Author Share Posted September 17, 2006 Nice Tips people thanks a bunch any more keep em coming. Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93497 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 onlyican Nice example try that my self cheers. Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93498 Share on other sites More sharing options...
onlyican Posted September 17, 2006 Share Posted September 17, 2006 If theres anything I missed there, let me knowbut I think My example covers everything, and I added the strtolower for username and passwordsMake it easier Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93499 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 is this the corect way to get the function to work on a diffrent page cheers.functions.php[code]<?phpfunction MakeSafe($str, $make_lower = false){if($make_lower){$str = strtolower($str);}$str = stripslashes($str);$str = trim($str);$str = strip_tags($str);$str = mysql_real_escape_string($str);}?>[/code]test.php[code]<?phpinclude("functions.php");function MakeSafe($str, $make_lower = false);$username = MakeSafe($_POST["username"], 1);//This will make string safe, keeping case, (For names ect)$name = MakeSafe($_POST["name"]);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93506 Share on other sites More sharing options...
Demonic Posted September 17, 2006 Author Share Posted September 17, 2006 no[code]<?phpinclude("functions.php");$username = MakeSafe($_POST["username"], 1);//This will make string safe, keeping case, (For names ect)$name = MakeSafe($_POST["name"]);?>[/code]All you have to do. Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93530 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 ok that becouse the function is being called witin the varables 4username and $name.get it.cheers. Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93533 Share on other sites More sharing options...
onlyican Posted September 17, 2006 Share Posted September 17, 2006 That has created a functiona function just like the things inside itmysql_real_escape_string is a functionstrtolower is a functionas long as its on the same page, it worksand using include or require puts it on the same page Quote Link to comment https://forums.phpfreaks.com/topic/21060-security-time-would-this-work/#findComment-93536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.