0

I am trying to declare HTTP PUT variable in php. This is my code:

<?php ${"_" . $_SERVER['REQUEST_METHOD']} = /* What should be here? */; ?> 

I tried var_dump($_SERVER) but it does not contain the data sent using ajax request. I am sure there is no problem with $.ajax().

12
  • 1
    Dear downvoter. Did you even understand what is my question? Commented Feb 5, 2018 at 8:47
  • “I tried var_dump($_SERVER) but it does not contain the data sent using ajax request” - and why should it …? lornajane.net/posts/2008/accessing-incoming-put-data-from-php, php.net/manual/en/features.file-upload.put-method.php Commented Feb 5, 2018 at 8:47
  • 2
    @CBroe Atleast the question is better than I am trying to run this code but it gives me error undefined variable, right? Commented Feb 5, 2018 at 8:49
  • 2
    @ErikKalkoken It is completely valid, try ${"_PUT"}="hi"; var_dump($_PUT); Commented Feb 5, 2018 at 8:54
  • 2
    @ErikKalkoken I understand, you were probably judging me on based of reputation. Rep is just a number :) Anyways, have a nice day :) Commented Feb 5, 2018 at 9:00

1 Answer 1

7

While there is no official $_PUT variable in PHP, you can create one yourself like this:

$method = $_SERVER['REQUEST_METHOD']; if ('PUT' === $method) { parse_str(file_get_contents('php://input'), $_PUT); var_dump($_PUT); //$_PUT contains put fields } 

Source: https://stackoverflow.com/a/41959141/4379151

Sign up to request clarification or add additional context in comments.

1 Comment

This is something that I was looking for, thank you for your time