Support » Fixing WordPress » wp-comments-post.php not reading REQUEST_METHOD correctly

  • An install that has been working just fine for 2 years has developed an intermittent problem. Sometimes comments are lost and the user gets a blank 405 error screen.

    I’ve narrowed it down to this line of code in /wp-comments-post.php

    if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {

    Even though var_dump’s show that REQUEST_METHOD is “POST”, this always is true and the code throws an error. I can fix this by changing it to :

    if ( ! 'POST' === $_SERVER['REQUEST_METHOD'] ) {

    …which is probably totally the wrong logic to stop bad requests getting in, but why is this working?

    And how can I fix this without changing this file every time I update WP?

    • This topic was modified 3 years, 3 months ago by Matt Rose. Reason: Probably wrong forum
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator t-p


    Both PHP errors and database errors can manifest as a white screen. This problem can be caused by a variety of issues, including:
    (1) Bad theme
    (2) Bad plugin
    (3) Bad install/upgrade
    (4) you exhausted the memory limit
    (5) It could also mean that there is an issue with your web hosting server.

    – 1 and 2 are more common.
    – Since the problem can be caused by any number of things, check the error logs on your server for a more specific error message. If you need help locating them, ask your hosting provider to help you with that.
    – If you cannot find error logs or if you don’t find any helpful info in them, try adding the following code to your wp-config.php directly above /* That’s all, stop editing! Happy blogging. */ : define( ‘WP_DEBUG’, true);
    – Try reviewing this useful Codex:

    Thanks @t-p but this is a core WP file that, at this line, has not even loaded WordPress. So it cannot be a bad theme / plugin, it hasn’t even loaded the database connection yet and the memory footprint is 1.56KB at this point. So I don’t think it’s those.

    Oh! and there are no PHP error messages, even with WP_DEBUG on (it hasn’t loaded WP yet)

    I thought it could be the hosting environment but if I add echo var_dump($_SERVER); after the headers that return the error. I can see 'REQUEST_METHOD' => "POST" so it must be getting through to PHP but something is triggering this error.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp-comments-post.php not reading REQUEST_METHOD correctly’ is closed to new replies.