Welcome Guest, Not a member yet? Register   Sign In
I cannot receive post data.
#1

[eluser]kjanko[/eluser]
Controller:
Code:
public function login()
    {
        $this->output->enable_profiler(TRUE);
        $this->load->library('trinity');
        $this->load->library('session');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        var_dump($username);
        var_dump($password);
        if($this->session->userdata('logged_in'))
        {
            show_error('You are already logged in!');
        }
        else
        {
            $this->trinity->Login($username, $password);
            redirect('home');
        }
    }

View:
http://pastebin.com/d1xXswhN

Login function:
Code:
public function Login($username, $password)
    {
        $auth = $this->_obj->config->item('DB_auth');
        $this->_trinity['auth'] = $this->_obj->load->database($auth, TRUE);
        $sha_password = sha1(strtoupper($password));
        $query = $this->_trinity['auth']->select('username, sha_pass_hash')->from('account')->where('username', $username)->where('sha_pass_hash', $sha_password)->get();
        if($query->num_rows() > 0)
        {
            $data = array(
                'username'      => $username,
                'password'      => $password,
                'logged_in'     => TRUE,
                'ip_address'    => $_SERVER['REMOTE_ADDR']
            );
            $this->_obj->session->set_userdata($data);
            redirect('home');
        }
        else
        {
            show_error('Invalid username or password. Please try again.');
        }
    }

$_POST is empty array.
#2

[eluser]Sudz[/eluser]
use this in view
Code:
<form method="post" action="<?php echo site_url('/home/login'); ?>" id="login_form">
#3

[eluser]kjanko[/eluser]
Didn't change anything, $_POST is still empty.
#4

[eluser]kjanko[/eluser]
I'd like to note that the site is hosted on my PC(http://localhost) and data is submitted just fine using the GET method. So this might be a bug in CI? (Almost the same version works on external host).
#5

[eluser]InsiteFX[/eluser]
And were is your login form?

InsiteFX
#6

[eluser]kjanko[/eluser]
http://pastebin.com/d1xXswhN

It's a widget on the homepage. I tried making a simple form and test again, however it didn't work out. I suspect It's a bug with CI. I can only access $_GET and cookie data on localhost, however I can't access $_POST nor I can access $_GET/$_POST via $_REQUEST.
#7

[eluser]InsiteFX[/eluser]
And why do you think its a bug with CI when everyone else can receive post data?
I think you will find that your problem is in your view code.

var_dump($value);
print_r
etc.

InsiteFX
#8

[eluser]kjanko[/eluser]
Because on my web host(http://delisium.com) the same method works just fine. On localhost It doesn't. Another user has been experiencing the same problems and he posted on this forum. I don't see anything wrong with my view file.
#9

[eluser]InsiteFX[/eluser]
Then what operating system and apache server software are you running?

I run Windows 7 Pro 64-bit with XAMPP 1.7.4 and have never had a problem with post data.

InsiteFX
#10

[eluser]Unknown[/eluser]
I have noticed that when I don't validate an input feild, it gets vanished.

kjanko try this code in place of your login function:
Code:
public function login()
{
    $this->output->enable_profiler(TRUE);
    $this->load->library('trinity');
    $this->load->library('session');
    
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'Username', 'trim');
    $this->form_validation->set_rules('password', 'Password', 'trim');
    
    if ($this->form_validation->run() == FALSE)
    {
        //You will never reach this code. It is just of debugging purpose;
        echo "In put data not valid";
        return;
    }
    
    $username = $this->input->post('username');
    $password = $this->input->post('password');
    var_dump($username);
    var_dump($password);
    if($this->session->userdata('logged_in'))
    {
        show_error('You are already logged in!');
    }
    else
    {
        $this->trinity->Login($username, $password);
        redirect('home');
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB