dlofrodloh
dlofrodloh

Reputation: 1744

How to completely ignore GET requests?

I have a php script which receives POST data as packets from my javascript aplication and processes it.

I'm having a problem where GET requests are being sent to it and interrupting the flow during runtime as it sends a blank response to my AJAX in my javascript. I haven't been able to track down the source of these requests despite a lot of effort, although they are coming from my IP.

How can I make my script completely ignore GET requests so ideally it doesn't even startup if a GET request is sent to it? (Not just die at the start if it's a get request which is what I have now).

Upvotes: 1

Views: 2117

Answers (2)

Yang
Yang

Reputation: 8711

How can I make my script completely ignore GET requests so ideally it doesn't even startup if a GET request is sent to it?

If so, then you need to ensure that request isn't GET before start doing another stuff.

if (strtoupper($_SERVER['REQUEST_METHOD']) === 'GET') {
  exit;
}

// Now do another stuff

P.S Be careful with overriding $_GET and another superglobals - this is because third-party libraries might use it (if you include a one in future)

Upvotes: 1

Lix
Lix

Reputation: 47986

You could just override the values within the $_GET variable at the start of your script:

unset( $_GET );

With regard to these variables "interrupting the flow during runtime" - the only way for this to happen is if you are actually using or parsing these parameters. Simply ignore them in the code: ie - don't reference it.

Upvotes: 0

Related Questions