{"id":255,"date":"2009-04-14T18:07:35","date_gmt":"2009-04-14T15:07:35","guid":{"rendered":"https:\/\/www.optimiced.com\/en\/?p=255"},"modified":"2009-04-14T19:17:55","modified_gmt":"2009-04-14T16:17:55","slug":"wordpress-capturing-prs-updated","status":"publish","type":"post","link":"https:\/\/www.optimiced.com\/en\/2009\/04\/14\/wordpress-capturing-prs-updated\/","title":{"rendered":"WordPress capturing $_POST requests (updated script)"},"content":{"rendered":"<p>A while ago, I discovered a <a href=\"http:\/\/www.village-idiot.org\/archives\/2008\/04\/03\/wordpress-capturing-_post-requests\/\">small and useful code snippet<\/a>, which allowed you to capture all <code>$_POST<\/code> activity, related to your WordPress blog.<\/p>\n<p>This might be useful when your WP-based website is experiencing a hacker attack. Or when you want to know where from is coming the biggest spam comment flood that try to drown your MySQL database in spam.<\/p>\n<p>After using this small code snippet for a while, I discovered a way to improve it a little bit.<\/p>\n<p>The original script didn&#8217;t show timestamps of the events recorded. I added this functionality, while leaving the original code almost the same.<\/p>\n<p>If you want to use this updated version, feel free to copy the code:<\/p>\n<pre lang=\"php\">\r\n$posty_ip = $_SERVER['REMOTE_ADDR'];\r\n$the_file = $_SERVER['SCRIPT_NAME'];\r\n$date_sub = date('Y-M-d @ H:i (O)');\r\nif ( $posty_ip != \"123.123.123.12\" && $posty_ip != \"123.123.123.23\" ) {\r\n  if ( !empty($_POST) ) {\r\n    $fp = fopen( '\/home\/path\/path-to-log.html', 'a' );\r\n    foreach( $_POST as $key => $value ) {\r\n\tfwrite( $fp, $key.' = '.$value.\" <br \/>\\n\" );\r\n\t}\r\n    fwrite( $fp, \"ip = \".$posty_ip.\" <br \/>\\n\" );\r\n    fwrite( $fp, \"date = \".$date_sub.\" <br \/>\\n\" );\r\n    fwrite( $fp, \"file = \".$the_file.\" <br \/>\\n\" );\r\n    fwrite( $fp, '================================================'.\" <br \/><br \/>\\n\\n\" );\r\n    fclose( $fp );\r\n  }\r\n}\r\n<\/pre>\n<p>I also added HTML line breaks, as for me it was more useful to have an HTML log file.<\/p>\n<p>The instructions where (and how) to place this code can be found in the <strong><a href=\"http:\/\/www.village-idiot.org\/archives\/2008\/04\/03\/wordpress-capturing-_post-requests\/\">original place<\/a><\/strong>. Still, it&#8217;s worth repeating: <strong>Be careful where you place the log file on your server<\/strong>!<\/p>\n<p>I would also recommend to use a plugin, which <a href=\"http:\/\/www.redsend.org\/chapsecurelogin\/ \">encrypts passwords<\/a> (you can download it from <a href=\"http:\/\/wordpress.org\/extend\/plugins\/chap-secure-login\/\">wordpress.org<\/a>). This is not obligatory, but it is always wise to send passwords over <strong>http<\/strong> encrypted, and this plugin does exactly that (you don&#8217;t have to use <strong>https<\/strong> to be able to encrypt the passwords being sent).<\/p>\n<p>Enjoy! :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while ago, I discovered a small and useful code snippet, which allowed you to capture all $_POST activity, related to your WordPress blog. This might be useful when your WP-based website is experiencing a hacker attack. Or when you want to know where from is coming the biggest spam comment flood that try to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":3,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/posts\/255\/revisions\/273"}],"wp:attachment":[{"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.optimiced.com\/en\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}