1

Codeigniter 正确加载登录页面,但在提交该表单时,浏览器响应 404 Not found。我不知道真正的问题是什么。请帮忙。下面是我们的代码:

这是我的视图文件:view/login/index.php

<?= form_open(base_url().'login/index', array('id' => 'loginForm')) ?>
<div class="wrap-login">
    <div id="content1">
        <div id="main">
            <h1>Administrator Area</h1>
            <div class="full_w1">
        <div class="form">
                <?php if ($this->session->flashdata('message')) : ?>
                <?= $this->session->flashdata('message') ?>
                <?php endif; ?>
                <?= form_label(lang('username'), 'username', array('data-icon' => 'u')) ?>
                <?= form_input(array('name'=>'username','id'=>'username','value'=>set_value('username'),'class'=>'text','placeholder'=>'Enter Username')) ?>
                <?= form_error('username') ?>

                <?= form_label(lang('password'), 'password', array('data-icon' => 'p')) ?>
                <?= form_input(array('type'=>'password','name'=>'password','id'=>'password','class'=>'text','placeholder'=>'Enter Password')) ?>
                <?= form_error('password') ?>
                    <div class="sep"></div>                 
                  <?= form_submit('login', lang('login'), 'class="ok"' ) ?>
                </div></div>
            </div>
        </div>
    </div>
     <?=form_close()?>
<script type="text/javascript">
    $(document).ready(function()
    {
        $('#username').focus();
    });
</script>

这是我的控制器文件:控制器/登录

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */

    function __construct()
    {
        parent::__construct();

        // load model
        $this->load->model('Login_model','',TRUE);
    }

    public function index()
    {
        if ($this->privilege->logged_in){
            redirect('dashboard/');         
        }

        // SET VALIDATION RULES
        $valid = array(
                   array(
                         'field'   => 'username', 
                         'label'   => lang('username'), 
                         'rules'   => 'trim|required|min_length[4]|max_length[15]|xss_clean'
                   ),
                   array(
                         'field'   => 'password', 
                         'label'   => lang('password'), 
                         'rules'   => 'trim|required|md5'
                   )
                 );

        $this->form_validation->set_rules($valid);
        $this->form_validation->set_error_delimiters('<div class="error">','</div>');

        // has the form been submitted and with valid form info (not empty values)
        if($this->input->post('login'))
        {echo "Hi";die;
            if($this->form_validation->run())
            {
                $returnValue = $this->Login_model->authenticate();
                if($returnValue == 'Active')
                {
                    //echo "<pre>"; print_r($this->session->userdata('sessionkey')); echo "</pre>"; die;
                    $this->session->set_flashdata('message','<div class="alert success" id="msgDiv"><span class="hide" id="hideMsg">x</span>You have successfully logged-in!!</div>');
                    redirect('dashboard/');
                }
                else
                {
                    $this->session->set_flashdata('message', '<div class="error">'.lang($returnValue).'</div>');
                    redirect('login/');
                }
            }
        }
        $data['title'] = "Administrator Area";
        $this->load->view('common/login-header',$data);
        $this->load->view('login/index');
        //$this->load->view('common/footer');
    }

    public function logout()
    {
        if($this->session->sess_destroy()) {
            $this->session->set_flashdata('message','<div class="alert success" id="msgDiv"><span class="hide" id="hideMsg">x</span>You have successfully logged-out!!</div>');
            redirect('login/');
        }
        else {
            redirect('dashboard/');
        }
    }
}
4

2 回答 2

1

这是修改后的工作代码

更改您的表单操作'http://85.195.86.86/index.php/login/index'

在此处输入图像描述

这是你的' hi!':)

在此处输入图像描述

总结: 如果您想使用现有的' ',请从 ' ' byurl中删除 ' ' 。您可以在 Google 上搜索 ' 'index.phpurl.htaccessHow to remove index.php in CI

.ht 访问代码:

Options -Indexes
Options +FollowSymLinks

RewriteEngine On

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin   

ErrorDocument 404 /index.php

CI 配置文件更改:

$config['base_url'] = '';

$config['index_page'] = '';
于 2013-07-11T09:50:38.083 回答
0

如果您尚未从您的 url 中删除 index.php,这似乎您尚未删除,那么

<?= form_open(base_url().'index.php/login/index', array('id' => 'loginForm')) ?>
于 2013-07-11T10:13:33.673 回答