0

I am writing a server script using CodeIgniter to store html code into database. My client send a json package contain a html string:

<table style='width:50%'

but from my server side I can only get from $this->post():

<table >

Do you know what wrong?


My full error log:

My JSON from the client side (encode by $.param from AngularJS):

apikey=superrocket_51f0c7333392f&faqid=31&categoryid=44&question=How+to+format+the+answer+%3F&answer=%3Ctable+style%3D'width%3A50%25%3B'%3E&displayorder=0

My PHP code to handle the JSON:

function updateFAQs_post(){
    $auth = $this->_auth();
    if ($auth){
        print_r($this->post('answer'));
        $this->load->model('Admin_model');
        $faqid = $this->Admin_model->updateFAQs($this->post('faqid'), $this->post('categoryid'), $this->post('question'), $this->post('answer'), $this->post('displayorder'));
        $response = array('success' => 'update done', 'faqid' => $faqid, 'index' => $this->post('index'));
        $this->response($response, 200);
    }
}

What I get from server:

<table >{"success":"update done","faqid":null,"index":false}

The faqid and index = null is expected. It has nothing to do with the error.

I think the error is due to the difference between the way JavaScript encode and the way PHP decode JSON package ?

3 Answers3

2

try

$this->input->post()

not $this->post()

$_POST works because thats raw php function

He Hui
  • 2,196
  • 4
  • 29
  • 46
0

I solved the problem by replacing $this->post('answer') by $_POST['answer'].

Still don't know that happened but it works

  • You might want to check out this: http://stackoverflow.com/questions/3788476/codeigniter-disable-xss-filtering-on-a-post-basis I'm pretty sure it has to do with the XSS cleaning, so you could disable this temporarily. But much better would be to not have any style tag at all, maybe you could work with a css class instead. That shouldn't trigger the XSS filter – mgrueter Jul 25 '13 at 08:54
0
$this->post('answer');

Should be

$this->input->post('answer');
Pooshonk
  • 1,284
  • 2
  • 22
  • 49