$_SERVER['REQUEST_METHOD'] always "GET"

I have Googled and not figured this out, I am sure it’s something stupid. I am always getting “get” back from $_SERVER[‘REQUEST_METHOD’] even if the form method is “post”. Any help would be appreciated.

Most likely explanation: your form markup is wrong, and the $_SERVER value is in fact correct. Start by validating your markup at http://validator.w3.org/. If it validates and you’re still having trouble, pastebin your markup so we can take a look.

Thanks, that is a great tool. I cleaned up a couple of warnings and it works now.

Well not so fast. Post seemed to work a few times then stopped. Here is my markup:


<!DOCTYPE html>
<html lang="en-US">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Test Forms</title>
</head>

<body>

	<form method="GET" name="getform" action="http://xxx.com/xxx/split.php">
		<input type="submit" value="Test Get" />
	</form>

	<br>
	<form method="POST" name="postform" action="http://xxx.com/xxx/split.php">
		<input type="submit" value="Test POST" />
	</form>
	
	
</body>
</html>

if I add a simple


<?php echo $_SERVER['REQUEST_METHOD']; ?>

to your markup, I get the proper result for both a GET and a POST, respectively.

I think it’s a problem on my server, another server worked fine.

Chances are it’s working, and your diagnostic is wrong.


<?php var_dump($_POST, $_GET, $_SERVER); >?

will probably be enlightening.

Also, if you’re not already using something similar, getfirebug.com.

It looks like it was because I was using a full URL for the ‘action=…’

That’s not the cause. You have two symptoms: REQUEST_METHOD is sometimes not what you expect; and putting a full URL in the action attribute alters behaviour. I don’t know why, but changing the action hasn’t fixed it, just masked some other problem.