在codeigniter中提交登录页面后找不到404 404

时间:2013-07-11 06:52:03

标签: codeigniter

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

这是我的查看文件: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>

这是我的控制器文件:controller / login

<?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/');
        }
    }
}

2 个答案:

答案 0 :(得分:1)

这是修改后的工作代码

使用'http://85.195.86.86/index.php/login/index'

更改您的表单操作

enter image description here

这是你的'hi!':)

enter image description here

<强>综述: 如果您想使用现有的“url”,请在“index.php”之后移除“url.htaccess。 您可以使用Google“How to remove index.php in CI

进行搜索

.htaccess代码:

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'] = '';

答案 1 :(得分:0)

如果你还没有从你的网址中删除index.php,这似乎还没有删除,而不是

<?= form_open(base_url().'index.php/login/index', array('id' => 'loginForm')) ?>
相关问题