Welcome Guest, Not a member yet? Register   Sign In
$_POST and $this->input->post() are always empty on localhost site
#3

[eluser]ian[/eluser]
My View:

Code:
<h2>&lt;?php echo lang('user_login_header') ?&gt;</h2>

&lt;?php echo form_open('users/login', array('id'=>'login')); ?&gt;
&lt;?php if (validation_errors()): ?&gt;
    <div class="error-box">&lt;?php echo validation_errors();?&gt;</div>
&lt;?php endif; ?&gt;
    
<ul class="reset">    

<li class="field">
    <label for="email">&lt;?php echo lang('user_email')?&gt;</label>
    &lt;input type="text" name="email" maxlength="120" value="&lt;?php echo $user_data-&gt;email; ?&gt;" />
</li>

<li class="field">
    <label for="password">&lt;?php echo lang('user_password')?&gt;</label>
    &lt;input type="password" name="password" maxlength="20" value="&lt;?php echo $user_data-&gt;password; ?&gt;" />
</li>

<li class="field checkboxes">
    &lt;?php echo form_checkbox('remember', '1', FALSE, 'class="checkbox"'); ?&gt; <label for="remember">&lt;?php echo lang('user_remember')?&gt;</label>
</li>
</ul>

<div class="buttons">
    &lt;input class="submit" type="submit" value="&lt;?php echo lang('user_login_btn') ?&gt;" name="btnLogin" /&gt;
</div>
    
&lt;?php echo form_close(); ?&gt;

<p>&lt;?php echo anchor('users/reset_pass', lang('user_reset_password_link'));?&gt; | &lt;?php echo anchor('register', lang('user_register_btn'));?&gt;</p>

My Controller Function:
Code:
public function login()
    {

        // Get the user data
        $user_data = (object) array(
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password')
        );
        
        // Validation rules
        $this->validation_rules = array(
            array(
                'field' => 'email',
                'label' => lang('user_email_label'),
                'rules' => 'required|trim|callback__check_login'
            ),
            array(
                'field' => 'password',
                'label' => lang('user_password_label'),
                'rules' => 'required|min_length[6]|max_length[20]'
            ),
        );

        // Set the validation rules
        $this->form_validation->set_rules($this->validation_rules);
        
        // Set the redirect page as soon as they get to login
        if(!$this->session->userdata('redirect_to'))
        {
            $uri = parse_url($this->input->server('HTTP_REFERER'), PHP_URL_PATH);

            // If iwe aren't being redirected from the userl ogin page
            $root_uri = BASE_URI == '/' ? '' : BASE_URI;
            strpos($uri, '/users/login') !== FALSE || $this->session->set_userdata('redirect_to', str_replace($root_uri, '', $uri));
        }
        
        // If the validation worked, or the user is already logged in
        if ($this->form_validation->run() or $this->ion_auth->logged_in())
        {
            $redirect_to = $this->session->userdata('redirect_to')
                ? $this->session->userdata('redirect_to')
                : ''; // Home

            $this->session->unset_userdata('redirect_to');

            // Call post login hook
            $this->hooks->_call_hook('post_user_login');

            // Redirect the user
            redirect($redirect_to);
        }

        // Render the view
        $this->data->sBodyClass = 'one-col';
        $this->data->user_data =& $user_data;
        $this->template->build('login', $this->data);
    }

My .htaccess
Code:
php_value upload_max_filesize 32M
php_value post_max_size 32M
php_value max_execution_time 200
# Error Logging
php_flag display_errors on
php_value error_reporting 9

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    
    #RewriteBase /wherever/pyro/is

    # Keep people out of codeigniter directory and Git/Mercurial data
    RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

I'll be happy to post anything from my config.php file, but I don't want to post the whole thing if not necessary.

I noticed I wasn't able to login to the page, so I initially thought it was a Session problem, but the first thing I tried was to print out the variables I was passing. Trying to print to the error log with
Code:
log_message('error', $this->input->post('email'));
gave me nothing.

When I put
Code:
var_dump($user_data);
after filling that array in the first few lines of the login() function, I get this printed out:
object(stdClass)#36 (2) { ["email"]=> bool(false) ["password"]=> bool(false) }


Messages In This Thread
$_POST and $this->input->post() are always empty on localhost site - by El Forum - 06-20-2011, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB