0

I've spent most of today trying to work out why my CodeIgniter application returns empty $_POST (and $this->input->post(<var>) and php://input) - I'd reduced the application down to a utterly minimal example of a single form input element and echoing $_POST.

As requested, the files (but, as far as I can see, this is irrelevant to my question of why the lack of the .htaccess rules prevents POST data being submitted through the framework):

The controller was this:

<?php
  class Form extends CI_Controller {
    public function __construct() {
      parent::__construct();
      $this->load->helper('form');
      $this->output->enable_profiler(TRUE);
    }

    public function form_show() {
      $this->load->view("form");
    }

    public function data_submitted() {
      $data['user_name'] = $this->input->post('u_name');
      $this->load->view("form-success", $data);
    }
  }
?>

form(.php) was:

<html>
<head></head>
<body>
<?php
  echo form_open('Form/data_submitted');
  echo form_label('User Name :', 'u_name');
  $form_data = array('name' => 'u_name');
  echo form_input($form_data);

  $submit_data = array(
    'type' => 'submit',
    'value'=> 'Submit',
  );
  echo form_submit($submit_data); ?>
  echo form_close();

  if(isset($user_name)){
    echo "<p>".$user_name."</p>";
  } ?>
</body>
</html>

form-success(.php) was

<?php var_dump($this->_ci_cached_vars); ?>
<html>
<head></head>
<body>
<?php print_r($_POST); ?>
</body>
</html>

I then realised I didn't have a .htaccess in my root folder - so restored CodeIgniter's default .htaccess file of

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 

But I can't work out which one of these (or why) allows POSTed data to be passed to the controller, but removing these rules doesn't allow it. Any light anyone can shed on this would be hugely appreciated to help satisfy my curiosity!

ChrisW
  • 4,970
  • 7
  • 55
  • 92
  • can you please share your controller and view file code here? – prakash tank Dec 31 '16 at 19:00
  • That `RewriteRule` in `.htaccess` only maps the URL based on what you type in the address bar. The first two `RewriteCond` checks if the path you type must not be a directory which is for !-d or a file which is for !-f and once those two conditions are met, the `RewriteRule` will be taken effect. Whatever you type will be passed as `index.php/$1`. $1 is what you type in the address bar which is captured through `(.*)`. Hope you got it. – Wolverine Dec 31 '16 at 19:24
  • @prakashtank contents of files added, but I don't think they have an direct relevance on my question of the lack of the `.htaccess` rules preventing POST data from being accessed by CodeIgniter – ChrisW Dec 31 '16 at 22:36
  • @Perumal93 - yes, that's what I thought they did, but why does the **lack** of them prevent POST data being accessed by CodeIgniter? – ChrisW Dec 31 '16 at 22:42
  • It seems peculiar. I'm not sure what causes your posted data to not pass through. Check out this similar question. http://stackoverflow.com/questions/5208450/codeigniter-from-post-data-not-going-through – Wolverine Jan 01 '17 at 13:05
  • @Perumal93 yes, I'd already looked at that answer, and tried everything suggested there – ChrisW Jan 01 '17 at 13:45

0 Answers0