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

4
  • 1
    stackoverflow.com/questions/2934554/… Commented Mar 4, 2014 at 13:15
  • 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, <form method='PUT' ...> will not cut it at this point in time. Commented Mar 8, 2014 at 7:18
  • @chiliNUT here is the put request note that this is genereated by backbone js model Commented Mar 8, 2014 at 7: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 Commented Mar 10, 2014 at 5:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.