0

I am in the process of updating the long overdue CI 2.something to CI 3.1.11. So far so good except for the form data which is lost. Neither $this->input->post('usr') nor $_POST hold any values at all. Empty!

After looking through some answers I figured that my htaccess might be at fault – however it does seem to do its job alright in every other case...

I run PHP 7.3.9 on Apache2. mod_rewrite is on.

Here is my htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]


</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

It might be the htaccess file OR something else. Any ideas?

UPD: To add to confusion: the Apache log for this one request at vhost http://esp.atlas.local reads:

127.0.0.1 - - [19/Oct/2019:23:00:42 +0200] "POST /admin/ HTTP/1.1" 301 236
127.0.0.1 - - [19/Oct/2019:23:00:42 +0200] "GET /admin HTTP/1.1" 200 4592

UPD2: The confusion is cleared: I submit the form to the same URL which means it first posts to it and then gets the HTML view from it.

Anyway, I am starting to question my morality as I've tried every possible htaccess configuration (even got one from Lumen/Laravel project I run on the same machine) and I either get nothing or I get 403 forbidden (which is new, but still doesn't solve anything). Any further ideas?

pop
  • 3,464
  • 3
  • 26
  • 43
  • 1
    I'm guessing this is already answered elsewhere. Forget the CodeIgniter piece and focus on `$_POST` is empty... if none of the answers in [this question](https://stackoverflow.com/questions/1282909/php-post-array-empty-upon-form-submission) are the answer, please indicate in the question and show you've handled each of them... – random_user_name Oct 18 '19 at 16:17
  • Probably the problem is here `RewriteRule ^(.*)/$ /$1 [L,R=301]`, maybe your form action does end with a trailing slash – Kerkouch Oct 18 '19 at 16:24
  • 1
    Possible duplicate of [$\_POST empty after form submit with htaccess redirect](https://stackoverflow.com/questions/28967659/post-empty-after-form-submit-with-htaccess-redirect) – Kerkouch Oct 18 '19 at 16:26
  • Ok, thanks for the help, but nothing had worked so far. even `php://input` is empty. Trailing slash is there. – pop Oct 19 '19 at 21:01

1 Answers1

0

Ok, so that was a CodeIgniter issue, as my htaccess, form method, form URL, etc were alright. Every other URL was working. Only $_POST was getting 403...

The problem was that csrf_token protection was set to true and as no token was present, CI has just thrown 403. I had to actually search for the error string within the installation directory to see what the problem was. Duh.

Here is my htaccess for anyone else getting into similar issues (3 lost days, Carl!)

<IfModule mod_rewrite.c>

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

</IfModule>
pop
  • 3,464
  • 3
  • 26
  • 43