Code Iginiter Error'地址未被理解'

时间:2016-04-21 04:53:12

标签: php mysql codeigniter xampp codeigniter-3

我'带有mysql数据库的新手代码iginiter 3和xampp v3.2。

错误'地址未被理解'当我点击登录按钮。 帮助我...

此配置

<code>`enter code here`
$config['base_url'] = 'localhost:8087/hris/';
$config['index_page'] = 'login.php';
</code>

和我的route.php

<code>
$route['default_controller'] = 'user_authentication';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
</code>

如何修复此错误....

user_authentication.php

Class User_Authentication extends CI_Controller 
{
     //session_start(); //we need to start session in order to access it      through CI
   public function __construct() 
   {
      parent::__construct();
      // Load form helper library
     $this->load->helper('form');
    // Load form validation library
    $this->load->library('form_validation');
    // Load session library
    $this->load->library('session');
    // Load database
    $this->load->model('login_database');
  }
  // Show login page

 public function index() 
 {
    $this->load->view('login');
 }
// Show registration page

public function user_registration_show() 
{
  $this->load->view('registration_form');
}
// Validate and store registration data in database

public function new_user_registration() 
{
   // Check validation for user input in SignUp form
   $this->form_validation->set_rules('username', 'Username','trim|required|xss_clean');
   $this->form_validation->set_rules('email_value', 'Email', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

if ($this->form_validation->run() == FALSE) 
{
   $this->load->view('registration_form');
} else 
  {
    $data = array(
           'user_name' => $this->input->post('UserID'),
           'user_email' => $this->input->post('email_value'),
           'user_password' => $this->input->post('password')
    );
   $result = $this->login_database->registration_insert($data);

if ($result == TRUE) 
{
   $data['message_display'] = 'Registration Successfully !';
   $this->load->view('login_form', $data);
} else {
   $data['message_display'] = 'Username already exist!';
   $this->load->view('registration_form', $data);
}
}
}
// Check for user login process

public function user_login_process() 
{
     $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

if ($this->form_validation->run() == FALSE) 
{
   if(isset($this->session->userdata['logged_in']))
   {
      $this->load->view('admin_page');
   }else{
      $this->load->view('login_form');
  }
} else {
   $data = array(
           'username' => $this->input->post('username'),
            'password' => $this->input->post('password')
     );
  $result = $this->login_database->login($data);

if ($result == TRUE) 
{
    $username = $this->input->post('username');
   $result = $this->login_database->read_user_information($username);
   if ($result != false) 
   {
       $session_data = array(
                       'username' => $result[0]->user_name,
                       'email' => $result[0]->user_email,
           );
// Add user data in session
    $this->session->set_userdata('logged_in', $session_data);
    $this->load->view('admin_page');
}
} else {
      $data = array(
   'error_message' => 'Invalid Username or Password'
   );
   $this->load->view('login_form', $data);
}
}
}
// Logout from admin page
public function logout() 
{
  // Removing session data
    $sess_array = array(
                    'username' => ''
        );
     $this->session->unset_userdata('logged_in', $sess_array);
     $data['message_display'] = 'Successfully Logout';
     $this->load->view('login_form', $data);
}
}
?>



this models login_database.php


Class Login_Database extends CI_Model 
{
       // Insert registration data in database
    public function registration_insert($data) 
    {
        // Query to check whether username already exist or not
        $condition = "user_name =" . "'" . $data['user_name'] . "'";
        $this->db->select('*');
        $this->db->from('user_login');
        $this->db->where($condition);
        $this->db->limit(1);
        $query = $this->db->get();

        if ($query->num_rows() == 0) 
        {

            // Query to insert data in database
              $this->db->insert('user_login', $data);
             if ($this->db->affected_rows() > 0) 
             {
                return true;
             }
        } else {
          return false;
}
}

// Read data using username and password
public function login($data) 
{

    $condition = "user_name =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
    $this->db->select('*');
    $this->db->from('user_login');
    $this->db->where($condition);
    $this->db->limit(1);
    $query = $this->db->get();

    if ($query->num_rows() == 1) {
      return true;
    } else {
       return false;
  }
 }

// Read data from database to show data in admin page
public function read_user_information($username) {

$condition = "user_name =" . "'" . $username . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();

 if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}

}

this view ( login.php )

$this->load->helper('form'); 
if (isset($this->session->userdata['logged_in'])) {
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
} 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Global stylesheets -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
    <link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/core.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/components.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/colors.min.css" rel="stylesheet" type="text/css">
    <!-- /global stylesheets -->

    <!-- Core JS files -->
    <script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
    <script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
    <script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
    <!-- /core JS files -->

    <!-- Theme JS files -->
    <script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>

    <script type="text/javascript" src="assets/js/core/app.js"></script>
    <script type="text/javascript" src="assets/js/pages/login.js"></script>
    <!-- /theme JS files -->
</head>
<body>
    <!-- Main navbar -->
    <div class="navbar navbar-inverse">
        <div class="navbar-header">
            <a class="navbar-brand" href="index.html"><img src="assets/images/logo_light.png" alt=""></a>

            <ul class="nav navbar-nav pull-right visible-xs-block">
                <li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
            </ul>
        </div>


    </div>
    <!-- /main navbar -->


    <!-- Page container -->
    <div class="page-container login-container">

        <!-- Page content -->
        <div class="page-content">

            <!-- Main content -->
            <div class="content-wrapper">

                <!-- Content area -->
                <div class="content">
                <?php
                echo form_open('user_authentication/user_login_process'); 
                ?>
                    <!-- Advanced login -->
                    <form action="" method="post">
                        <div class="panel panel-body login-form">
                            <div class="text-center">
                                <div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
                                <h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control" placeholder="Username" name="userid" id="userid" required> 
                                <div class="form-control-feedback">
                                    <i class="icon-user text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control" placeholder="Password" name="pass" id="pass" required>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group login-options">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label class="checkbox-inline">
                                            <input type="checkbox" class="styled" checked="checked">
                                            Remember
                                        </label>
                                    </div>

                                    <div class="col-sm-6 text-right">
                                        <a href="login_password_recover.html">Forgot password?</a>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <button type="submit" class="btn bg-blue btn-block">Login <i class="icon-arrow-right14 position-right"></i></button>
                            </div>

                        <?php echo form_close(); ?>

                            <div class="content-divider text-muted form-group"><span>Don't have an account?</span></div>
                            <a href="login_registration.html" class="btn btn-default btn-block content-group">Sign up</a>
                        </div>
                    </form>
                    <!-- /advanced login -->
                </div>
                <!-- /content area -->
            </div>
            <!-- /main content -->
        </div>
        <!-- /page content -->
    </div>
    <!-- /page container -->
</body>
</html>

</pre></code>

2 个答案:

答案 0 :(得分:0)

尝试将您的表单更改为此

<?php
  echo form_open(base_url('User_Authentication/user_login_process')); 

  ?>

答案 1 :(得分:0)

对于遇到地址不明的人,例如,当单击链接时,只需确保将http://添加到$config['base_url']值中,对于上述问题,您应该替换:

$config['base_url'] = 'localhost:8087/hris/';

作者

$config['base_url'] = 'http://localhost:8087/hris/';

希望获得帮助:)