Welcome Guest, Not a member yet? Register   Sign In
$this->input->post() Broken Returned Data
#1

I'm using codeigniter 3.0.4 . I've experienced a problem and created a test structure for describe it here like below:

Code:
function dene1(){
$url = site_url('Giris/dene2');
$myvars = '_search=true&nd=1453717819822&rows=42&page=1&sidx=&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22HTH2%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22%3E7.5%2B%3C10%22%7D%2C%7B%22field%22%3A%22ST1Y%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22100%22%7D%2C%7B%22field%22%3A%22ST2Y%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22%3E55%2B%3C100%22%7D%5D%7D';
echo '<h3>MYVAR ORIGINAL:</h3><code>'.$myvars.'</code><hr/>';
echo '<h3>MYVAR URLDECODED:</h3><code>'.urldecode($myvars).'</code><hr/>';

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
echo '<h3>MYVAR $this->input->post() RESPONCE:</h3><code>'.$response.'</code>';
}

function dene2(){
print_r($this->input->post());
}
   

This functions are in a controller.

When i visit site http://localhost:81/index.php/giris/dene1.html site; returned values like below:

Code:
MYVAR ORIGINAL:

_search=true&nd=1453717819822&rows=42&page=1&sidx=&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22HTH2%22%2C%22op%22%3A%22eq%22%2C%22data%22%3A%22%3E7.5%2B%3C10%22%7D%2C%7B%22field%22%3A%22ST1Y%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22100%22%7D%2C%7B%22field%22%3A%22ST2Y%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22%3E55%2B%3C100%22%7D%5D%7D
MYVAR URLDECODED:

_search=true&nd=1453717819822&rows=42&page=1&sidx=&sord=asc&filters={"groupOp":"AND","rules":[{"field":"HTH2","op":"eq","data":">7.5+<10"},{"field":"ST1Y","op":"cn","data":"100"},{"field":"ST2Y","op":"cn","data":">55+<100"}]}
MYVAR $this->input->post() RESPONCE:

Array ( [_search] => true [nd] => 1453717819822 [rows] => 42 [page] => 1 [sidx] => [sord] => asc [filters] => {"groupOp":"AND","rules":[{"field":"HTH2","op":"eq","data":">7.5+<10>55+<100"}]} )
   

I want to describe these structure. I have defined myvars string for post data to another controller function. I shown urldecoded style of myvars variable for simple understanding. And shown output of $this->input->post() .

As you can see; post() function is brakes HTH2 field and removes ST2Y field. (These are coming from jqgrid).

When i use
Code:
$input=file_get_contents('php://input');
$_GET = array();
parse_str($input, $_GET);

structure for gater input data, everything works well but $this->input->post() brakes data.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#2

Your mistake is that you are mixing url encoded parameters and JSON object. HTH2 field is not part of the POST variables, but its part of JSON object pasted in the "filters" parameter.

The proper way would be:
1. Get POST variable "filters"
2. JSON_decode it
3. Then get the needed fields (HTH2, ST2Y, etc)
Reply
#3

(01-27-2016, 07:43 PM)siburny Wrote: Your mistake is that you are mixing url encoded parameters and JSON object. HTH2 field is not part of the POST variables, but its part of JSON object pasted in the "filters" parameter.

The proper way would be:
1. Get POST variable "filters"
2. JSON_decode it
3. Then get the needed fields (HTH2, ST2Y, etc)

No, his problem was using the global_xss_filter: https://github.com/bcit-ci/CodeIgniter/issues/4397

... and cross-posting.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB