Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter登录问题_Php_Codeigniter_Login - Fatal编程技术网

Php Codeigniter登录问题

Php Codeigniter登录问题,php,codeigniter,login,Php,Codeigniter,Login,我很难理解这里发生了什么 我创建了一个登录页面,将其设置为转到管理页面。没有任何用户数据,只是为了检查它是否工作。它不走了。加载库表单验证时遇到一些问题。所以我添加了父构造 控制器 public function __construct() { parent::__construct(); $this->load->helper('url'); } public function index() { //$this->load->view(

我很难理解这里发生了什么

我创建了一个登录页面,将其设置为转到管理页面。没有任何用户数据,只是为了检查它是否工作。它不走了。加载库表单验证时遇到一些问题。所以我添加了父构造

控制器

public function __construct() {
    parent::__construct();
    $this->load->helper('url'); 

}

public function index() {

    //$this->load->view('login');
    $this->load->view('login');

}

public function login() {

    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->helper('url'); 
    $this->form_validation->set_rules('username','Username','trim|required');
    $this->form_validation->set_rules('password','Password','trim|required|md5');
    if($this->form_validation->run()==false){
        $this->index();
    }else{
        $user_session=array(
            'Username'      => $this->input->post('username'),
            'Password'      => $this->input->post('password'),
            'is_logged_in'  => 1
        );
        $this->session->set_userdata('userlogin',$user_session);
        $this->admin();
    }

}

public function admin() {
    $this->load->view('admin');

}
我的登录视图

 <section class="login_content">
        <?php echo validation_errors(); ?>
        <form action="<?php echo base_url().'login/login'; ?>" method="post">
        <h1>Login no Sistema</h1>
        <div>
            <input type="text" name="username" class="form-control" placeholder="Username" required="" />
        </div>
        <div>
            <input type="password" name="password" class="form-control" placeholder="Password" required="" />
        </div>
        <div>
            <input type="submit" name="submit" value="Login" />

        </div>
        <div class="clearfix"></div>
        <div class="separator">


          <div class="clearfix"></div>
          <br />
          <div>
            <h1> Sitio Monica e Marcia</h1>

            <p>©2016 Todos os direitos reservados. Sitio Monica e Marcia.</p>
          </div>
        </div>
      </form>
      <!-- form -->
    </section>

试试这个

重定向(基本url(“登录/管理”)

试试这个


重定向(基本url(“登录/管理”)

这是您的控制器

public function __construct() {
    parent::__construct();
    $this->load->helper('url'); 

}

public function index() {

    //$this->load->view('login');
    $this->load->view('login');

}

public function login() {

    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->helper('url'); 
    $this->form_validation->set_rules('username','Username','trim|required');
    $this->form_validation->set_rules('password','Password','trim|required|md5');
    if($this->form_validation->run()==false){
        $this->index();
    }else{
        $user_session=array(
            'Username'      => $this->input->post('username'),
            'Password'      => $this->input->post('password'),
            'is_logged_in'  => 1
        );
        $this->session->set_userdata('userlogin',$user_session);
        $this->admin();
    }

}

public function admin() {
    $this->load->view('admin');

}

这是你的控制器

public function __construct() {
    parent::__construct();
    $this->load->helper('url'); 

}

public function index() {

    //$this->load->view('login');
    $this->load->view('login');

}

public function login() {

    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->helper('url'); 
    $this->form_validation->set_rules('username','Username','trim|required');
    $this->form_validation->set_rules('password','Password','trim|required|md5');
    if($this->form_validation->run()==false){
        $this->index();
    }else{
        $user_session=array(
            'Username'      => $this->input->post('username'),
            'Password'      => $this->input->post('password'),
            'is_logged_in'  => 1
        );
        $this->session->set_userdata('userlogin',$user_session);
        $this->admin();
    }

}

public function admin() {
    $this->load->view('admin');

}

首先,我不知道Login.php文件或类Login extensed CI_Controller是否是保留名称,请尝试更改它


然后您有一个名为login()的公共函数,这可能与构造函数有关,因为在php5或更高版本中,您像调用类名一样调用构造函数,并且可能会先重写构造函数,我不知道login.php文件或类login extensed CI_Controller是否是保留名称,请尝试更改它


然后您有一个名为login()的公共函数,这可能与构造函数有关,因为在php5或更高版本中,您像调用类名一样调用构造函数,并且您可能会重写构造函数。我认为,您应该检查您的链接和会话。这是密码

控制器中的login.php

<div class="container" height=100%>
  <h2>Welcome to the system, 
    <?php 
        $this->load->library('session');
        $login_session = $this->session->userdata('userlogin');
        //$username = $this->session->userdata('userlogin');
        echo $login_session['Username'];
    ?>
  </h2>
</div>
视图中的login.php


我想,你应该检查你的链接和会话。这是密码

控制器中的login.php

<div class="container" height=100%>
  <h2>Welcome to the system, 
    <?php 
        $this->load->library('session');
        $login_session = $this->session->userdata('userlogin');
        //$username = $this->session->userdata('userlogin');
        echo $login_session['Username'];
    ?>
  </h2>
</div>
视图中的login.php


您是否尝试过
$this->admin()
而不是
重定向('login/admin')
?好的,它不是重定向('login/admin');就这么做了。还是一样…你收到错误信息了吗?您是否检查了apache错误日志?同时请检查来自
$this->form\u validation->run()
函数的响应您是否尝试了
$this->admin()
而不是
重定向('login/admin')
?好的,它不是重定向('login/admin');就这么做了。还是一样…你收到错误信息了吗?您是否检查了apache错误日志?还请检查来自
$this->form\u validation->run()
函数的响应
<form class="form-horizontal" role="form" action="<?php echo 'http://localhost/answers/index.php/login/login'; ?>" method="post">
    <div class="form-group">
      <label class="control-label col-sm-2" for="username">Username:</label>
      <div class="col-sm-10">
        <input type="username" class="form-control" id="username" name="username" placeholder="Enter username">
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Password:</label>
      <div class="col-sm-10">          
        <input type="password" class="form-control" id="password" name="password" placeholder="Enter password">
      </div>
    </div>
    <div class="form-group">        
      <div class="col-sm-offset-2 col-sm-10">
        <div class="checkbox">
          <label><input type="checkbox"> Remember me</label>
        </div>
      </div>
    </div>
    <div class="form-group">        
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">Login</button>
      </div>
    </div>
  </form>
<div class="container" height=100%>
  <h2>Welcome to the system, 
    <?php 
        $this->load->library('session');
        $login_session = $this->session->userdata('userlogin');
        //$username = $this->session->userdata('userlogin');
        echo $login_session['Username'];
    ?>
  </h2>
</div>