0

我刚开始使用 CI,我正在尝试登录。我已经阅读了一些教程,然后尝试自己制作一个,但它不起作用。当我尝试登录 ig 时出现错误:

在此服务器上找不到请求的 URL /Helptor/login_controller/going_in。

我尝试了很多东西,但没有任何效果。

这是我登录视图中的登录表单:

<form action="<?php echo base_url();?>login_controller/going_in" method="post" name="going_in">
<?php if(! is_null($msg)) echo $msg;?>
<table style="font-size: 30px;">
    <tr>
        <td>Username: </td>
        <td><input type="text" size="45" name="username" style="background-color: #C5D2F5;"/></td>
    </tr>
    <tr>
        <td>Password: </td>
        <td><input type="password" size="45" name="password" style="background-color: #C5D2F5;"/></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" value="Login" style="border-width: 2px; height: 40px; width: 120px; font-family: Calibri; font-size: 22px; background-color: #FEFEFF;"></td>
    </tr>
    <tr>
        <td><a href="?lang=en"><img src="<?= base_url() ?>assets/img/United_Kingdom(Great_Britain).png"/></a>&nbsp;
            <a href="?lang=nl"><img src="<?= base_url() ?>assets/img/Netherlands.png"/></a>
        </td>
    </tr>
</table>

登录控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class login_controller extends CI_Controller{

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

public function index($msg = NULL){
    $this->load->database();
    $this->load->helper('url');
    $data['msg'] = $msg;
    $this->load->view('login', $data);
}

public function going_in(){
    // Load the model
    $this->load->model('login_model');
    // Validate the user can login
    $result = $this->login_model->validate();
    // Now we verify the result
    if(! $result){
        // If user did not validate, then show them login page again
        $msg = '<font color=red>Invalid username and/or password.</font><br />';
        $this->index($msg);
    }else{
        // If user did validate, 
        // Send them to members area
        redirect('user');
    }        
  }
}
?>

登录模型:

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

class Login_model extends CI_Model{
function __construct(){
    parent::__construct();
}

public function validate(){
    // grab user input
    $username = $this->security->xss_clean($this->input->post('username'));
    $password = $this->security->xss_clean($this->input->post('password'));

    // Pre ping the query
    $this->db->where('username', $username);
    $this->db->where('password', $password);

    // Run the query
    $query = $this->db->get('users');
    //check for results
    if($query->num_rows == 1)
    {
        //create session data
        $row = $query->row();
        $data = array(
                'id' => $row->ID,
                'username' => $row->Username,
                'level' => $row->Level,
                'validated' => true
                );
        $this->session->set_userdata($data);
        return true;
    }
    return false;
  }
}
?>

基本网址:

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

索引页:

$config['index_page'] = '';

uri_protocol:

$config['uri_protocol'] = 'AUTO';

更新

我在地图应用程序中的 .htaccess 文件如下所示

拒绝一切

更新 2

这是我的文件夹结构:

localhost/helptor
 -application
   -controllers
     -index.html
     -login_controller.php
     -user.php
   -models
     -login_model.php
     -index.html
   -views
     -.htaccess
     -index.html
     -login.php
     -user.php
   .htaccess
   index.html
 -assets
 -system
 index.php
4

3 回答 3

2

如果你在 www/helptor 工作,试试这个:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /helptor/index.php/$1 [L]

以后部署到另一台服务器时,您应该记住删除此“helptor”字符串。

于 2014-09-07T20:02:27.273 回答
2

我知道这有点太晚了,但这对我有用。

您应该将 Apache AllowOverride 策略设置为 all。这是我为该站点添加到我的 .conf 中的内容。

<Directory "/var/www/yoursite">
    Options -Indexes
    AllowOverride All
</Directory>
于 2016-08-02T23:42:46.560 回答
0

快速阅读 CodeIgniter 文档 ( http://ellislab.com/codeigniter/user-guide/general/urls.html ) 指向.htaccess他们推荐的 URL 语法:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

试试这个,看看这是否能解决问题。

于 2013-11-12T10:28:23.663 回答