RESTFullYii does not get data for PUT request - php

I use RESTFullYii v1.15 from here . RESTFullYii does not get data for PUT request
I faced the problem that making PUT method the data I submit are not inside the doRestUpdate($id, $data) function.
In the link above it is defined as public function doRestUpdate($id, $data).
So it is supposed that data are submit are in $data variable.
Vars $_GET, $_POST, $_REQUEST don't have these data too.
I watch headers of request using firebug and see that data are sent in PUT request, but they are not in doRestUpdate function.
If there is way to fix it?

Related

Is there a equal predefined variable like $_REQUEST in code-igniter?

The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms.
Is there a way in code igniter to access GET and POST both data through one predefined variable or function
You can use
$this->input->post_get('some_data', TRUE);
This will work like $_REQUEST.More function are there like cookie,server.
For more information check here

$_POST not populated

I'm having some issues with the PHP REST API of my app.
I'm submitting my parameters in the correct URL format: baseUrl?param1=val1&param2=val2
However, the parameters are being filled into the $_GET array instead. I've looked into the $_SERVER array to see if there is something wrong there, but I can't see anything obvious.
$_SERVER['CONTENT_TYPE']="application/x-www-form-urlencoded"
$_SERVER['REQUEST_METHOD']="POST"
I've also checked my php.ini for post_max_size misconfig:
post_max_size=32M
I'm not able to figure what else could cause the parameters to be placed into $_GET
If it helps, I'm using XAMPP on Windows.
Also, using "Advanced REST client" for Chrome, I've noticed that regardless of the method, POST parameters are placed into $_GET if the parameters are in the URL, but if I move them into the REST client's Payload field, they show up as POST parameters.
You cannot get parameters via $_POST which are submitted in query-string. You can get them via $_GET array.
but if I move them into the REST client's Payload field, they show up as POST parameters., seeing your trouble, you can always get them with $_REQUEST
Just sharing a thought, The place from where you are initiating post request to backend, you have to use post method.
For example if you are using jquery
$.ajax ({ type: 'POST' })
If angular js
$http.post({ 'your code' });

Uploading file with PUT method in PHP

For my RESTFUL API server I'm trying to use the "PUT" method for uploading a file.
Actions started as reading php://input.
So, how can pass file name or some other parameters to action and display them?
You can use post method therefore, you can collect data from form-data using $_POST the super global variable because, there is no super global like $_PUT for put method.

$_POST empty in PHP file but call it with POST variables in the URL

I call my php file in the browser with "...test.php?text=Hello" but the $_POST variable stays empty (also print_r($_POST) returns array() ).
Why? Do I need to activate the post variable or something?
Thanks.
Variables passed in through the URL end up inside $_GET, not $_POST.
$_POST contains variables parsed by reading the HTTP request body when the method is POST. In this case the method is not POST and there is also no request body.
If you pass the variable through the URL you use $_GET.
Also, you will access the variable with:
$_GET['text']
This is a array that is sent through and you need to specify what item in the array you want to use.
...test.php?text=hello passes data via the GET method (accessible via $_GET in the processing script).
$_POST gets populated by forms or cURL access (when the transfer method is defined as "post")

POST or GET in XMLHttpRequest

What does post mean in the following?
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("POST", "url" + queryString, true);
because i'm not able to access variables using $_POST['var'] from url but
with $_REQUEST['var'] I can access value..
When you read from $_POST, you should pass your arguments in the HTTP body instead of using the querystring.
You would need to send your arguments as in the following example:
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("POST", "your_service.php", true);
ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxRequest.send("var=100&another_var=200");
Your are not able to access the parameters via $_POST because you append them to the URL (i.e. they can be accessed via $_GET) and don't send them as POST data.
If you want to send the parameters via POST, have a look at the send() method.
POST is something included in an HTTP request (such as an XMLHTTPRequest).
In your case, you are adding the query string to the URL, which means that it is being passed as a GET variable. Even if it is a post request, PHP can still access any GET variables added on as a query string.
Based on your code, I don't think you are telling the request what info should be included in the POST section of the request, which would explain why you are not seeing anything with $_POST['var'].
But since $_REQUEST['var'] looks for request variables in GET and POST and any cookies passed in the request, you see the variable as it was passed via the query string.
Try echoing $_GET['var'] and you'll see that this is where the variable is getting the data from.
If you want to use POST the right way, you need to not point the request to a URL that has a query string and instead define that query string as the post data.
The post does mean the values are posted, but you should add them as post variables, while now you are only adding them to the url so you can only get them with $_REQUEST and $_GET.
Post data is usually passed in via the post data.
IIRC, you can pass it as an object via the send method.
ajaxRequest.send(requestString)

Categories