Jump to content
  • Advertisement
Sign in to follow this  
Colin Jeanne

[web] [PHP] Using HTTP DELETE

This topic is 3651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to setup a PHP application on my Dreamhost site to handle HTTP DELETE requests but whenever I test it the server bypasses my app and returns 503. Is there something that needs to be configured to allow DELETE to be used? I dont intend to have the server automatically delete the resource, I want to handle the deletion myself. For reference, and if it's important, PHP is being run using FastCGI. This is the simple test page I wrote as a test index.php
if ($_SERVER['REQUEST_METHOD'] != 'GET') {
   echo $_SERVER['REQUEST_METHOD'];
   //echo file_get_contents('php://input');
   exit;
}

echo <<<EOL
<html>
<head>
<title>test</title>
<script language="javascript">
   function sendMe() {
      var form = document.getElementById('test');
      var xmlHTTP = new XMLHttpRequest();
      var thing = document.getElementById('thing');
      
      function handler() {
         if (xmlHTTP.readyState == 4) {
            thing.innerHTML = xmlHTTP.responseText;
         }
      }
      
      xmlHTTP.onreadystatechange = handler;
      xmlHTTP.open("DELETE", "/", true);
      xmlHTTP.send("/phpinfo.php");
   }
</script>
</head>
<body>
<form id="test">
<textarea name="test"></textarea>
<input type="button" onclick="sendMe()" />
</form>
<div id="thing"></div>
</body>
</html>
EOL;
exit;

Share this post


Link to post
Share on other sites
Advertisement
Ugh, looks like there are two problems here: 1) I suck at writing HTTP command directly via Telnet, 2) there seems to be a bug in Firefox where it doesnt handle the DELETE method properly for XMLHttpRequest.

I tried using cURL to use DELETE and it worked perfectly. I tried the example page in IE7 and Opera 9.5 and it worked perfectly.

Time to find or file a bug against Firefox.

Share this post


Link to post
Share on other sites
Personally I'd use prototype for anything like this mainly because it takes into account cross-browser issues like this.

I found this resource, not sure if it helps:
http://dobrzanski.net/2007/04/22/using-put-and-delete-methods-in-ajax-requesta-with-prototypejs/

Share this post


Link to post
Share on other sites
Duh. My bad. I thought PUT and DELETE were part of WebDAV.

BTW, I found a nice bug here: http://opensourcesmall.biz/archives/2007/11/rest-php-put-and-webdav-on-apache/

Apparently there's a bug in the Apache's mod_dav that makes it respond to all PUTs and DELETEs on a server, so that they never pass on to PHP.

Share this post


Link to post
Share on other sites
That's definitely something I'll need to keep in mind if I ever redeploy my code or start messing around with WebDAV. However, my PHP app is actually getting and processing PUT and DELETE properly - as long as it's not Firefox that's sending them. Even then, Firefox seems to only have trouble with DELETE.

That's not such a big issue since the idea of supporting the Atom Publishing Protocol is to make the site work with rich client apps.

Share this post


Link to post
Share on other sites
I am working with Ruby on Rails, it uses a lot of PUT, and DELETE (for updating and deleting content). The problem is that most of the browser doesn't implement all the HTTP protocol. So to have PUT and DELETE to work on all navigators, Rails add an hidden field in his forms, with the real method.


<form action="/pages" method="post">
<input type="hidden" name="_method" value="put"/>
< !-- Rest of the form here -- <
</form>


Hope it will help

[Edited by - bibiskuk on June 23, 2008 12:47:34 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!