Jump to content
Fórum Script Brasil
  • 0

Login com CodeIgniter


Paulo Amaral
 Share

Question

Olé estou começando com CodeIgniter, e já tenho problema no login do sistema.
Apos inserir os dados nos campos "nome" e "senha" e submeter o formulário me retorna os seguintes erros:


A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\automac\system\database\drivers\mysqli\mysqli_driver.php:221)
Filename: core/Common.php
Line Number: 569
Backtrace:


A PHP Error was encountered
Severity: Error
Message: Maximum execution time of 60 seconds exceeded
Filename: mysqli/mysqli_driver.php
Line Number: 221
Backtrace:

segue os códigos

login_model.php(Model)

	if (! defined('BASEPATH')) exit('No direct script access allowed');
	
	class Login_model extends CI_Model {
		
		//Validação do usuário		
		public function validacao($usuario, $senha){
			
			$this->db->where('USUARIO', $usuario);
			$this->db->where('SENHA', $senha);
			
			$query = $this->db->get('DBA');
			
			
			if($query->num_rows == 1){
				print_r($query);
				die();	
				return true; // retorna verdadeiro
			}
		}
		
		//Verifica se usuário esta logado
		public function logado(){
			$logado = $this->session->userdata('logado');
			
			if(!isset($logado) || $logado != true){
				echo 'Voce nao tem permissao para entrar nessa pagina!';
            	die();
			}
		}
	}

login.php(Controller)

	if (! defined('BASEPATH')) exit('No direct script access allowed');
	class Login extends CI_Controller{
		function __construct(){
			parent:: __construct();
		}
		
		public function index(){
			
			//Validacao
			$this->load->library('form_validation');
			$this->form_validation->set_rules('usuario', 'Usuário', 'required');
			$this->form_validation->set_rules('senha', 'Senha', 'required');
			$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
			
			
			//Modelo Login
			$this->load->model('login_model', 'MLogin');
			$usuario = $this->input->post('usuario');
			$senha   = $this->input->post('senha');
			$query = $this->MLogin->validacao($usuario,$senha);
			
			if($this->form_validation->run() == FALSE){
				$this->load->view('v_login');
			}else{
				if($query){ // Verifica Login  e Senha
					$data = array(
						'usuario' =>$this->input->post('usuario'),
						'logado' => true
					);
					$this->session->set_userdate($data);
					redirect('principal');
				}else{
					redirect($this->index());
				}
			}
			
			
		}
	}

v_login.php(view)

			<?php echo form_open();?>
				<div class="body bg-gray">
					<div class="form-group" id="loginGroup">
						<?php echo form_error('usuario', '<div class="error">', '</div>'); ?>
						<div class="input-group">
							<span class="input-group-addon"><i class="fa fa-user"></i></span>
							<?php
            					echo form_input(array(
									"name" => "usuario",
									"class" => "form-control",
									"placeholder" => "Informe o Usuário"
								));
								?>						
						</div>						
					</div>
					
					<div class="form-group">
						<?php echo form_error('senha', '<div class="error">', '</div>'); ?>
						<div class="input-group" id="senhaGroup">
							<span class="input-group-addon"><i class="fa fa-lock"></i></span>
							
							<?php								
								echo form_password(array(
									"name" => "senha",
									"class" => "form-control",
									"placeholder" => "Informe a Senha"
								)); 
							?>
						</div>
					</div>					
				</div>				
				<div class="footer bg-gray">
					<?php 
						echo form_submit(array(
							"name" => "submit",
							"class" => "btn bg-orange",
							"value" => "Acessar"
						))
					?>
				</div>
			<?php form_close(); ?>
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...