After logging in, the I display the dashboard, but the URL isn't "/dashboard", after logging in this is the URl displayed: http://localhost/tools2/login/validate_credentials
I want it to be http://localhost/tools2/dashboard and when I enter this URL I don't get anything displayed.
this is the code responsible for the login in the "controllers" section:
login.php
// Validation function: Checks if the user is in the 'users' DB and logs him in.
function validate_credentials(){
$this->load->helper('url');
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->model('membership_model');
$query = $this->membership_model->validate($email, $password);
if ( $query ) { // if the user's credentials validated...
$data = array(
'email' => $email,
'is_logged_in' => TRUE
);
$this->session->set_userdata($data);
$this->load->view('dashboard');
} else {
$this->index();
}
}
dashboard.php
<?php
class Dashboard extends CI_Controller{
// This is the first function to be called here.
function index(){
$this->load->view('header');
$this->load->view('dashboard');
$this->load->view('footer');
}
}
login form:
<div id="login_form">
<?php if ( isset($account_created) ) { ?>
<h3> <?php echo $account_created; ?> </h3>
<?php } else { ?>
<h1>Login, Please. </h1>
<?php } ?>
<?php
echo form_open('login/validate_credentials');
echo form_input('email', 'Email');
echo form_password('password', '', 'placeholder="Password" class="password"');
echo form_submit('submit', 'Login');
echo anchor('login/signup', 'Create Account');
echo form_close();
?>
<?php echo validation_errors('<p clas="error">'); ?>
</div> <!-- END login_form -->
Try this
function validate_credentials(){
$this->load->helper('url');
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->model('membership_model');
$query = $this->membership_model->validate($email, $password);
if ( $query ) { // if the user's credentials validated...
$data = array(
'email' => $email,
'is_logged_in' => TRUE
);
$this->session->set_userdata($data);
redirect('Dashboard');
} else {
$this->index();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.