{"id":1845,"date":"2014-01-23T08:23:43","date_gmt":"2014-01-23T16:23:43","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1845"},"modified":"2014-03-25T17:54:32","modified_gmt":"2014-03-26T00:54:32","slug":"injection-attacks-revisited","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1845","title":{"rendered":"Injection attacks revisited."},"content":{"rendered":"<p>I thought I\u2019d share another injection attack defense that I use on my sites. You can buy my stuff from Gumroad and I have a page where I list all of the Mac titles and a page where I list all of the Windows titles. I use one php script for both and there are only two choices for the page variable, &#8216;Mac&#8217; or &#8216;Win&#8217;. It should\u2019t happen but I allow for no values as well.<\/p>\n<p><pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n\/\/ I get the data for the page from a database, and you need one if you use \n\/\/ mysql_real_escape_string() so it goes first.\nrequire_once(&#039;db_my.inc&#039;);\n\nif ( isset($_GET[&#039;page&#039;]) ) { \n&nbsp;&nbsp;&nbsp;&nbsp;$platform&nbsp;&nbsp;= mysql_real_escape_string($_GET[&#039;page&#039;]); \n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Platform can only be Mac or Win, so make injection attacks go away\n&nbsp;&nbsp;&nbsp;&nbsp;if ( strlen($platform) &gt; 3 ) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$url = $_SERVER[&#039;REQUEST_URI&#039;];\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ref = $_SERVER[&#039;HTTP_REFERER&#039;];\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error_log(&quot;long string in CDs.php: URL is $url and referrer is $ref&quot;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header(&quot;HTTP\/1.0 404 Not Found&quot;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die();\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n\/\/ If there is no $platform, they probably want to buy a title that works on \n\/\/ the platform they are visiting the site with\n}&nbsp;&nbsp;else { \n&nbsp;&nbsp;&nbsp;&nbsp;$user_agent = $_SERVER[&#039;HTTP_USER_AGENT&#039;]; \n&nbsp;&nbsp;&nbsp;&nbsp;$platform = &#039;Win&#039;; \/\/ Default to windows\n&nbsp;&nbsp;&nbsp;&nbsp;if (preg_match(&#039;\/macintosh|mac os x\/i&#039;, $user_agent)) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$platform = &#039;Mac&#039;;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I thought I\u2019d share another injection attack defense that I use on my sites. You can buy my stuff from Gumroad and I have a page where I list all of the Mac titles and a page where I list all of the Windows titles. I use one php script for both and there are &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1845\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Injection attacks revisited.<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1845","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1845"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1845\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}