Jump to content

$_Server['request_Method'] Not In Index


markhutch

Recommended Posts

It's been a while since I coded PHP so I'm more than happy to admit I've made a newbie mistake somewhere - but I don't see where!

 

If I view the following in a browser I get everything I would normally expect:

 

http://localhost/?phpinfo=1

 

Including:

_SERVER["REQUEST_METHOD"] GET

 

 

However, when I have the following code:

if ($_SERVER["REQUEST_METHOD"]=="POST") { ...

 

I get this error:

PHP Notice: Undefined index: REQUEST_METHOD in C:\Documents and Settings\Administrator\Local Settings\Application Data\ActiveState\KomodoIDE\6.1\samples\php_tutorials\guestbook.php on line 40

 

(The code above is line 40 of course :)

 

There are SOME $_SERVER values that I can access, like SCRIPT_NAME or PATH_TRANSLATED. Just not the ones I'm trying to access.

 

What am I missing?? This is being run on a freshly installed WampServer 2.2.

Link to comment
Share on other sites

You could do like this:

 

$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null;

if ($requestMethod == 'post') {
// Post request
}

 

Or like this:

 

if (!empty($_POST)) {
// Post request
}

Edited by Andy123
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.