Dillion & Amanda 4 Lif Posted June 4, 2010 Posted June 4, 2010 Well, since i know alot of people use the strip_slashes() function, i want to help out. As anyone knows magic quotes are better to not be used in scripts. However, strip_slashes() relies on them. Heres an alternative, ridiculously easy function you can use. I recommend putting it in a file that you include on every page. <?php function stripslashes($text){ return str_replace(array("\\","/"), array("",""), $text); } ?> The main reason i use this is because i escape data on input, and i dont like slashes because of quotes in my names of things, so this way its safe inside the db, and you dont have a bunch of slashes ruining your stuff :) Quote
Djkanna Posted June 4, 2010 Posted June 4, 2010 stripslashes does not rely on magic_quotes. Also if you have magic_quotes disabled there is no need to stripslashes() on output from the database :) Quote
Dillion & Amanda 4 Lif Posted June 4, 2010 Author Posted June 4, 2010 An example use of stripslashes() is when the PHP directive magic_quotes_gpc is on (it's on by default), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form. ? Quote
Djkanna Posted June 4, 2010 Posted June 4, 2010 magic_quotes adds addslashes() to all $_GET, $_POST,$_COOKIE.. If magic_quotes is disabled (like I mentioned in my previous post) there is no addslashes added to those var's to therefor no need to use stripslashes(). As magic_quotes is deprecated and removed as of PHP 6.0 (I think that's right) there will be no use of stripslashes in the instance of how it's being used to date. As for databases addslashes() escapes it then you happen to use for example mysql(i)_real_escape_string() which would en up being: (example) This little Piggy wasn\\'t home for Dinner(/example) Which gives the misconception of stripslashes needed when using mres or addslashes however this is not the case the reason you end up with a / in the database is because you're double escaping(not a good thing) the said variable so ofcourse you want to get rid of the extra backslash(or is it a forward slash :S ) hense the use of stripslashes. Now if magic_quotes is disabled and you use an escaping function inside a query it would look like : (example)mysql_query("UPDATE `blah` SET `blah` = 'This little Piggy wasn\'t home for dinner' ") (/example) In the database it would look like: Blah: This little Piggy wasn't home for dinner Wait a minute no slash? So that then renders the stripslashes() on output that you did useless at best. Quote
Dillion & Amanda 4 Lif Posted June 4, 2010 Author Posted June 4, 2010 magic_quotes adds addslashes() to all $_GET, $_POST,$_COOKIE.. If magic_quotes is disabled (like I mentioned in my previous post) there is no addslashes added to those var's to therefor no need to use stripslashes(). As magic_quotes is deprecated and removed as of PHP 6.0 (I think that's right) there will be no use of stripslashes in the instance of how it's being used to date. As for databases addslashes() escapes it then you happen to use for example mysql(i)_real_escape_string() which would en up being: (example) This little Piggy wasn\\'t home for Dinner(/example) Which gives the misconception of stripslashes needed when using mres or addslashes however this is not the case the reason you end up with a / in the database is because you're double escaping(not a good thing) the said variable so ofcourse you want to get rid of the extra backslash(or is it a forward slash :S ) hense the use of stripslashes. Now if magic_quotes is disabled and you use an escaping function inside a query it would look like : (example)mysql_query("UPDATE `blah` SET `blah` = 'This little Piggy wasn\'t home for dinner' ") (/example) In the database it would look like: Blah: This little Piggy wasn't home for dinner Wait a minute no slash? So that then renders the stripslashes() on output that you did useless at best. Ahh ok. Quote
rulerofzu Posted June 4, 2010 Posted June 4, 2010 Thats correct magic quotes is depreciated from PHP 5.3.0 and removed from PHP 6 Quote
Djkanna Posted June 4, 2010 Posted June 4, 2010 Thats correct magic quotes is depreciated from PHP 5.3.0 and removed from PHP 6 Thanks for confirming that I wasn't too sure XD Quote
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.