Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with codeigniter's redirect function
    primarykey
    data
    text
    <p>This may be a n00b topic but, anyways, I have been having a rather difficult and strange time with this bug. Basically I was working on a controller method for a page that displays a form. Basically, I was debugging the form's submitted data by var dumping the form input using codeigniter's <code>$this-&gt;input-&gt;post</code> function like so: </p> <pre><code>var_dump($this-&gt;input-&gt;post('first_name')); </code></pre> <p>Every other day this has worked, but today I was finding that when I dumped post variables to the browser it would return false as if they had no values even though they did have values when I submitted the form. Then I tried accessing the variables through PHP's POST superglobal array directly like so:</p> <pre><code>var_dump($_POST['first_name']); </code></pre> <p>and that returned empty as well so then I tried dumping the entire post array like so:</p> <pre><code>var_dump($_POST); </code></pre> <p>and it was empty as well despite the fact that I filled out the entire form. Nevertheless, the records in my MySQL database were being updated (which means that the form was submitting even though my $_POST variables appeared empty). </p> <p>Also, I reasoned that normally, if I var dumped variables in the controller function before a redirect function call that it should give me a 'Headers already sent' error but it never did. It just redirected me to the supposed success page instead of dumping my variables. </p> <p>So for the about 2 hours I thought that my POST data wasn't being sent and re-checked the code for errors and began commenting out statements one by one until I could find the culprit statement in my script.</p> <p>Finally, I commented out a chunk of code that sets a success message an redirects, like so:</p> <pre><code>/* if($record_updated_successfully) { $this-&gt;session-&gt;set_flashdata('success', $this-&gt;lang-&gt;line('record-updated-successfully')); } redirect('admin/success_page'); */ </code></pre> <p>and only then did the script start dumping out all my previous variable dumps using codeigniter's <code>$this-&gt;input-&gt;post</code> function as well as the <code>$_POST</code> superglobal array.</p> <p>So ok, if the script does indeed redirect me despite the variable dumps sending output before headers are sent then I can see why the $_POST variables would appear empty.</p> <p>So then the real question is why the script would still redirect despite my sending of output before headers are sent? Has anyone ever experienced this?</p> <p>Any help with this would be appreciated.</p> <p>EDIT: with respect to loading the view here's a simplified version of my script looks like with the debugging var dump statements:</p> <pre><code>function some_controller_method() { var_dump($this-&gt;input-&gt;post()); var_dump($_POST); // some code if($this-&gt;input-&gt;post('form_action') == 'update record') { // code that runs when the form is submitted /* * ... */ if($record_updated_successfully) { $this-&gt;session-&gt;set_flashdata('success', $this-&gt;lang-&gt;line('record-updated-successfully')); } redirect('admin/success_page'); } $this-&gt;load-&gt;view('my-view-file.php'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload