{"id":651,"date":"2012-05-10T09:17:16","date_gmt":"2012-05-10T09:17:16","guid":{"rendered":"http:\/\/www.withinweb.com\/info\/?p=651"},"modified":"2012-06-20T13:30:34","modified_gmt":"2012-06-20T13:30:34","slug":"use-regular-expressions-to-validate-php-inputs","status":"publish","type":"post","link":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/","title":{"rendered":"Use regular expressions to validate PHP inputs"},"content":{"rendered":"<p>To help counter SQL injections you need to make sure that entered values use minimum character types as possible.\u00a0 So you restrict usernames to just a-z and 0-9 characters.<\/p>\n<p>To test for these, use something like :<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n\/**<br \/>\n* Purpose : Check input for paticular characters<br \/>\n* Only allow a &#8211; z, A &#8211; Z , 0-9<br \/>\n* returns true if a match was found, false if no match was found<br \/>\n* @return boolean<br \/>\n*\/<br \/>\nfunction is_valid_input($words) {<\/p>\n<p>if ( preg_match( &#8220;\/[^0-9a-zA-Z]\/&#8221;, $words, $array ) )<br \/>\nreturn false;\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/invalid characters<br \/>\nelse<br \/>\nreturn true;\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/valid characters<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To help counter SQL injections you need to make sure that entered values use minimum character types as possible.\u00a0 So you restrict usernames to just a-z and 0-9 characters. To test for these, use something like : \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \/** *<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/\">Read more <span class=\"screen-reader-text\">Use regular expressions to validate PHP inputs<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,11],"tags":[],"class_list":["post-651","post","type-post","status-publish","format-standard","hentry","category-reg-expressions","category-security-issues"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Use regular expressions to validate PHP inputs - PHP Web Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use regular expressions to validate PHP inputs - PHP Web Applications\" \/>\n<meta property=\"og:description\" content=\"To help counter SQL injections you need to make sure that entered values use minimum character types as possible.\u00a0 So you restrict usernames to just a-z and 0-9 characters. To test for these, use something like : \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \/** *&hellip;Read more Use regular expressions to validate PHP inputs &#8250;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Web Applications\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-10T09:17:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-06-20T13:30:34+00:00\" \/>\n<meta name=\"author\" content=\"paulv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"paulv\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/\"},\"author\":{\"name\":\"paulv\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"headline\":\"Use regular expressions to validate PHP inputs\",\"datePublished\":\"2012-05-10T09:17:16+00:00\",\"dateModified\":\"2012-06-20T13:30:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/\"},\"wordCount\":95,\"commentCount\":0,\"articleSection\":[\"Regular Expressions\",\"Security Issues\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/\",\"name\":\"Use regular expressions to validate PHP inputs - PHP Web Applications\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\"},\"datePublished\":\"2012-05-10T09:17:16+00:00\",\"dateModified\":\"2012-06-20T13:30:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/use-regular-expressions-to-validate-php-inputs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use regular expressions to validate PHP inputs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\",\"name\":\"PHP Web Applications\",\"description\":\"Information and support for products of WithinWeb.com\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\",\"name\":\"paulv\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/author\\\/paulv\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Use regular expressions to validate PHP inputs - PHP Web Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/","og_locale":"en_US","og_type":"article","og_title":"Use regular expressions to validate PHP inputs - PHP Web Applications","og_description":"To help counter SQL injections you need to make sure that entered values use minimum character types as possible.\u00a0 So you restrict usernames to just a-z and 0-9 characters. To test for these, use something like : \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \/** *&hellip;Read more Use regular expressions to validate PHP inputs &#8250;","og_url":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/","og_site_name":"PHP Web Applications","article_published_time":"2012-05-10T09:17:16+00:00","article_modified_time":"2012-06-20T13:30:34+00:00","author":"paulv","twitter_card":"summary_large_image","twitter_misc":{"Written by":"paulv"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/#article","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/"},"author":{"name":"paulv","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"headline":"Use regular expressions to validate PHP inputs","datePublished":"2012-05-10T09:17:16+00:00","dateModified":"2012-06-20T13:30:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/"},"wordCount":95,"commentCount":0,"articleSection":["Regular Expressions","Security Issues"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/","url":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/","name":"Use regular expressions to validate PHP inputs - PHP Web Applications","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/#website"},"datePublished":"2012-05-10T09:17:16+00:00","dateModified":"2012-06-20T13:30:34+00:00","author":{"@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"breadcrumb":{"@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.withinweb.com\/info\/use-regular-expressions-to-validate-php-inputs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.withinweb.com\/info\/"},{"@type":"ListItem","position":2,"name":"Use regular expressions to validate PHP inputs"}]},{"@type":"WebSite","@id":"https:\/\/www.withinweb.com\/info\/#website","url":"https:\/\/www.withinweb.com\/info\/","name":"PHP Web Applications","description":"Information and support for products of WithinWeb.com","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.withinweb.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c","name":"paulv","url":"https:\/\/www.withinweb.com\/info\/author\/paulv\/"}]}},"_links":{"self":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":5,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/651\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}