0

I'm trying to do a header redirect in PHP doing something like:

header("Location: http://www.domain.com/some/url");
exit;

This works fine when making a GET and POST request however it doesn't seem to work with PUT and DELETE requests.

I've tried doing:

header("Location: DELETE/PUT http://www.domain.com/some/url");
exit;

But that doesn't seem to work, also calling the url directly works fine. I can echo some text before and after the header call, so everything is working, seems to just ignore PUT and DELETE requests?

ggozad
  • 13,105
  • 3
  • 40
  • 49
Rob
  • 10,851
  • 21
  • 69
  • 109

2 Answers2

0

Using Location is not the proper way to set the HTTP Method header.

Try the following:

header("Request-Type: DELETE");
header("Location: http://www.domain.com/some/url");
exit;

However, I am not sure you can set request types with header() alone. I know you can with cURL.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
0

Similar question, possible same answer applies to you

The header function is used to send HTTP response headers back to the user (i.e. you cannot use it to create request headers.

May I ask why are you doing this? Why simulate a POST request when you can just right there and then act on the data someway? I'm assuming of course script.php resides on your server.

To create a POST request, open a up a TCP connection to the host using fsockopen(), then use fwrite() on the handler returned from fsockopen() with the same values you used in the header functions in the OP. Alternatively, you can use cURL.

PS: I see that it is also displayed under Linked tab :)

Community
  • 1
  • 1
Claudiu Hojda
  • 1,021
  • 9
  • 14