【发布时间】:2026-01-29 20:50:01
【问题描述】:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller
{
public function __construct()
{
parent::__construct();
//Model for fetching users in database
$this->load->model('user', '', TRUE);
}
public function index()
{
//Load method to help verify form credentials
$this->load->library('form_validation');
//-----------------------------------------------
//Verify Existance of values in login form fields
//-----------------------------------------------
//Validate existance of username field value
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
//Validate existance of password field value, and if exists then call 'check_database' func
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
//If the form validation is false (i.e. Missing form fields)
if($this->form_validation->run() == FALSE){
//Redirect back to login page
$this->load->view('general-Login');
}
//Login Success, goto main-page
else{
//Go to main page
redirect('Main', 'refresh');
}
}
function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//Check the username and password against database
$result = $this->user->login($username, $password);
//If there is a result
if($result){
//will be used for session information
$sess_array = array();
foreach ($result as $row){
$sess_array= array(
'id' => $row->id,
'username' => $row->username
);
//Session set as logged in
$this->session->set_userdata('logged_in', $sess_array);
}
return true;
}
//No existance of user or, incorrect password
else{
//Send Message of incorrect username or password
$this->form_validation->set_message('check_database', 'Invalid Username or Password');
return false;
}
}
}
所以我有一个验证登录控制器来处理来自我的登录页面的表单数据。数据库访问效果很好,一切正常,直到我使用重定向功能。我尝试通过刷新进行重定向,它只是给了我一个显示“未定义”的页面。现在,当我删除“刷新”并留下控制器名称时,它会突然起作用,但我试图弄清楚为什么这个“刷新”不起作用。
我已禁用我的.htaccess
我尝试将$config['uri_protocol'] 设置为REQUEST_URI、AUTO 和PATH_INFO
并没有运气。
另外,这是我第一次在网上提交给论坛之类的任何东西,所以请......温柔一点。
【问题讨论】:
标签: php codeigniter redirect controller codeigniter-2