{"id":4271,"date":"2009-09-29T12:55:32","date_gmt":"2009-09-29T19:55:32","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=4271"},"modified":"2009-09-29T12:58:29","modified_gmt":"2009-09-29T19:58:29","slug":"cleaning-variables","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/php\/cleaning-variables\/","title":{"rendered":"Cleaning Variables"},"content":{"rendered":"

Variables that are submitted via web forms always need to be cleaned\/sanitized before use in any way, to prevent against all kinds of different malicious intent.<\/p>\n

Technique #1<\/h4>\n
function clean($value) {\r\n\r\n       \/\/ If magic quotes not turned on add slashes.\r\n       if(!get_magic_quotes_gpc())\r\n\r\n       \/\/ Adds the slashes.\r\n       { $value = addslashes($value); }\r\n\r\n       \/\/ Strip any tags from the value.\r\n       $value = strip_tags($value);\r\n\r\n       \/\/ Return the value out of the function.\r\n       return $value;\r\n\r\n}<\/code><\/pre>\n
$sample = \"<a href='#'>test<\/a>\";\r\n$sample = clean($sample);\r\necho $sample;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Variables that are submitted via web forms always need to be cleaned\/sanitized before use in any way, to prevent against all kinds of different malicious intent. Technique #1 function clean($value) { \/\/ If magic quotes not turned on add slashes. if(!get_magic_quotes_gpc()) \/\/ Adds the slashes. { $value = addslashes($value); } \/\/ Strip any tags from […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3233,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":196684,"url":"https:\/\/css-tricks.com\/snippets\/sass\/px-to-em-functions\/","url_meta":{"origin":4271,"position":0},"title":"Px to Em Functions","date":"February 24, 2015","format":false,"excerpt":"We've talked about \"Why Ems?\" here before. For those new to em values, The Mozilla Developer Network does an excellent job of explaining ems: ...an em is equal to the size of the font that applies to the parent of the element in question. If you haven't set the font\u2026","rel":"","context":"With 18 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":155729,"url":"https:\/\/css-tricks.com\/lodge\/learn-jquery\/28-building-complex-plugin\/","url_meta":{"origin":4271,"position":1},"title":"#28: Building a More Complex Plugin","date":"November 11, 2013","format":false,"excerpt":"Now that we understand the basics of plugin development, we can dig a little deeper. Because ultimately a plugin is a function, it provides us the scope we need to organize. Remember when we got our house in order when we were learning about templating? We can use some of\u2026","rel":"","context":"With 3 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":191222,"url":"https:\/\/css-tricks.com\/snippets\/sass\/advanced-type-checking\/","url_meta":{"origin":4271,"position":2},"title":"Advanced Type Checking","date":"December 19, 2014","format":false,"excerpt":"This collection of functions is for testing if the value of a variable is of a certain type. For instance, is 13rem a relative length? TRUE! Is \"frosty the snowman\" and integer? FALSE! This is likely most useful for advanced mixin and framework creators who aim to make their code\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":194405,"url":"https:\/\/css-tricks.com\/snippets\/sass\/clamping-number\/","url_meta":{"origin":4271,"position":3},"title":"Clamping a Number","date":"January 28, 2015","format":false,"excerpt":"In computer science, we use the word clamp as a way to restrict a number between two other numbers. When clamped, a number will either keep its own value if living in the range imposed by the two other values, take the lower value if initially lower than it, or\u2026","rel":"","context":"With 1 comment","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":237831,"url":"https:\/\/css-tricks.com\/snippets\/sass\/power-function\/","url_meta":{"origin":4271,"position":4},"title":"Power Function","date":"February 9, 2016","format":false,"excerpt":"While very helpful with arithmetic, Sass falls a bit short with mathematical helper functions. There has been an open issue on the official repository to ask for more math-related functions for almost 3 years. Some third-party vendors like Compass or SassyMath provide advanced support for math features, but they are\u2026","rel":"","context":"With 5 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":192714,"url":"https:\/\/css-tricks.com\/snippets\/sass\/luminance-color-function\/","url_meta":{"origin":4271,"position":5},"title":"Color Luminance Function","date":"January 9, 2015","format":false,"excerpt":"When digging deep into color theory, there is something called relative color luminance. To put it simply, the luminance of a color defines whether its brightness. A luminance of 1 means the color is white. On the opposite, a luminance score of 0 means the color is black. Knowing the\u2026","rel":"","context":"With 9 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4271"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=4271"}],"version-history":[{"count":6,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4271\/revisions"}],"predecessor-version":[{"id":4277,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4271\/revisions\/4277"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3233"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=4271"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=4271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}