0

Develop a simple backbone and php application but on a server i get 403 error

whenever i use a put method

Of course when using more traditional method such as get and post i do not get any problem.

Could any one advise on what is the specific settings to tune because on another server it work great.

My suspects are

  1. apache configuration
  2. php configuration

Thanks in advance.

Code Sample

PHP file

$this -> method = $GLOBALS['_SERVER']['REQUEST_METHOD'] ;
switch ( $this -> method ) { 
case ( 'POST' ) : 
    foreach ( $_POST as $k => $v ) 
        $data -> $k = $v ;
    $data = $this -> save ($data) ;
    $this -> output( $data ) ;
    break 
case ( 'PUT' ) : 
    $putdata = fopen("php://input", "r");
    while ($d = fread($putdata, 1024))
        $data .= $d ;

    $data = json_decode( $data ) ; 
    $data = $this -> save ($data) ;
    $this -> output( $data ) ;                              
    break ;
case ( 'DELETE' ) :
    $data = $this -> delete($data) ;
    $this -> output( $data ) ;                              
    break ;

case ('GET') :
default:
    $data = $this -> retrieve () ;
    $this -> output( $data ) ;                              
    break ;
}

Note that backbone does not need form using jquery ajax to make an xhr request

arguments: {
    0: {
      contentType: "application/json"
      data: { 
        "id":0,
        "dat":"10-03-2014",
        "title":"Bunk bed",
        "current":false,
        "enrole":[],
        "result":"",
        "starts":{"m":{},"f":{}},"sex":"m"} 
  }
      dataType: "json"
      emulateHTTP: false
      emulateJSON: false
      error: function (resp) { ... }
      parse: true
      processData: false
      success: function (resp) { ... }
      type: "PUT"
      url: "event" // event is a folder with index.php
      validate: true
    }
}

Backbone.$.ajax.apply(Backbone.$, arguments);

Here is the request made by the browser

Request Method:PUT
Status Code:301 Moved Permanently
Request Headersview parsed
    PUT /maa/event HTTP/1.1
    Host: localhost
    Connection: keep-alive
    Content-Length: 123
    Cache-Control: no-cache
    Pragma: no-cache
    Origin: http://localhost
    X-Requested-With: XMLHttpRequest
    Content-Type: application/json
    Accept: application/json, text/javascript, */*; q=0.01
    User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
    Referer: http://localhost/maa/
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-US,en;q=0.8,fr;q=0.6,fr-FR;q=0.4
Request Payloadview parsed
    {"id":0,"dat":"10-03-2014","title":"Acton Vale","current":false,"enrole":[],"result":"","starts":{"m":{},"f":{}},"sex":"m"}

Everything work except for the put which generates a 301 error

Pascal
  • 2,377
  • 3
  • 25
  • 40
  • 1
    http://stackoverflow.com/questions/2934554/how-to-enable-and-use-http-put-and-delete-with-apache2-and-php – Digital Chris Mar 04 '14 at 13:15
  • @chiliNUT i have added some code thanks – Pascal Mar 08 '14 at 07:14
  • OK, thanks for the code. But what I was really trying to get at, is how are you making the PUT request? Please provide the client code too! AFAIK, `
    ` will not cut it at this point in time.
    – chiliNUT Mar 08 '14 at 07:18
  • @chiliNUT here is the put request note that this is genereated by backbone js model – Pascal Mar 08 '14 at 07:43
  • @chiliNUT thanks for taking the time to review note that backbone does not do a form submit but a xhr request i have add the argument sent to jquery ajax – Pascal Mar 10 '14 at 05:35

0 Answers0