loops - redirect looping on codeigniter -



loops - redirect looping on codeigniter -

after had changed codeigniter files , screen has diplay error this

http://webdomain.com/index.php/login/login has resulted in many redirects. clearing cookies site or allowing third-party cookies may prepare problem. if not, perchance server configuration issue , not problem computer. larn more problem. error code: err_too_many_redirects

it might cause infinity looping redirect , tried prepare few hr don't problem there code cant figure out whats error in code , used google chrome browser

my route default controller index.php

here login.php (controller) code

<?php if(!defined('basepath')) exit('error'); class login extends ci_controller{ public function __construct(){ parent::__construct(); $this->load->model('login_model'); $this->load->library('session'); $this->load->database(); $this->load->helper('url'); $this->load->helper('form'); $this->load->helper('security'); } public function index(){ redirect('login/login'); } public function login(){ if($this->session->userdata('logged_in')==true){ redirect ('login/login'); }else{ $this->load->library('form_validation'); //for view filters $this->form_validation->set_rules('username','username','required|min_length[5]|max_length[125]'); $this->form_validation->set_rules('password','password','required|min_length[5]|max_length[20]'); if($this->form_validation->run()==false){ $this->load->view('login/login_admin'); }else{ $username = $this->input->post('username'); $password = $this->input->post('password'); //$this->load->model('login_model'); $query=$this->login_model->data_pengguna($username,$password,1); if($query->num_rows()==1){ //jika benar foreach ($query->result() $row){ $this->load->library('encrypt'); //generate hash password $hash=$this->encrypt->sha1($password); //mengcompare result hash in database\ if($hash!=$row->hash){ //tidak sama $data['login_fail']=true; $this->load->view('login/login_admin',$data); }else{ $data=array( 'id'=>$row->user_id, 'username'=>$row->username, 'logged_in'=>true ); //menyimpan session $this->session->set_userdata($data); redirect ('login/home'); } } } } } } public function logout(){ $this->session->sess_destroy(); redirect('login/login_admin'); } } ?>

and here login_model.php (model) code

<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class login_model extends ci_model{ function __construct(){ parent::__construct(); $this->load->helper('url'); } public function get_pengguna($username, $password, $status){ $this->db->select('username','password','status'); $this->db->from('userlogin'); $this->db->where('username',$username); $this->db->where('password',$password); $this->db->where('status',$status); $query= $this->db->get(); homecoming $query->num_rows(); } public function data_pengguna($username){ $this->db->select('username'); $this->db->from('userlogin'); $this->db->where('username',$username); $query= $this->db->get('userlogin'); homecoming $query->row(); } } ?>

and here view login_admin.php code

<!doctype html> <html> <head> <meta charset="utf-8"> <title>admin login</title> <style> @import url(http://fonts.googleapis.com/css?family=exo:100,200,400); @import url(http://fonts.googleapis.com/css?family=source+sans+pro:700,400,300); body{ margin: 0; padding: 0; background: #fff; color: #fff; font-family: arial; font-size: 12px; } .body{ position: absolute; top: -20px; left: -20px; right: -40px; bottom: -40px; width: auto; height: auto; background-image: url(http://ginva.com/wp-content/uploads/2012/07/city-skyline-wallpapers-008.jpg); background-size: cover; -webkit-filter: blur(5px); z-index: 0; } .grad{ position: absolute; top: -20px; left: -20px; right: -40px; bottom: -40px; width: auto; height: auto; background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.65))); /* chrome,safari4+ */ z-index: 1; opacity: 0.7; } .header{ position: absolute; top: calc(50% - 35px); left: calc(50% - 255px); z-index: 2; } .header div{ float: left; color: #fff; font-family: 'exo', sans-serif; font-size: 35px; font-weight: 200; } .header div span{ color: #5379fa !important; } .login{ position: absolute; top: calc(50% - 75px); left: calc(50% - 50px); height: 150px; width: 350px; padding: 10px; z-index: 2; } .login input[type=text]{ width: 250px; height: 30px; background: transparent; border: 1px solid rgba(255,255,255,0.6); border-radius: 2px; color: #fff; font-family: 'exo', sans-serif; font-size: 16px; font-weight: 400; padding: 4px; } .login input[type=password]{ width: 250px; height: 30px; background: transparent; border: 1px solid rgba(255,255,255,0.6); border-radius: 2px; color: #fff; font-family: 'exo', sans-serif; font-size: 16px; font-weight: 400; padding: 4px; margin-top: 10px; } .login input[type=button]{ width: 260px; height: 35px; background: #fff; border: 1px solid #fff; cursor: pointer; border-radius: 2px; color: #a18d6c; font-family: 'exo', sans-serif; font-size: 16px; font-weight: 400; padding: 6px; margin-top: 10px; } .login input[type=button]:hover{ opacity: 0.8; } .login input[type=button]:active{ opacity: 0.6; } .login input[type=text]:focus{ outline: none; border: 1px solid rgba(255,255,255,0.9); } .login input[type=password]:focus{ outline: none; border: 1px solid rgba(255,255,255,0.9); } .login input[type=button]:focus{ outline: none; } ::-webkit-input-placeholder{ color: rgba(255,255,255,0.6); } ::-moz-input-placeholder{ color: rgba(255,255,255,0.6); } </style> <script src="js/prefixfree.min.js"></script> </head> <body> <?php echo form_open('login/login');?> <?php if (validation_errors()):?> <h3>there error</h3> <p><?php echo validation_errors();?></p> <?php endif;?> <div class="body"></div> <div class="grad"></div> <div class="header"> <div>login<span>admin</span></div> </div> <br> <div class="login"> <input type="text" placeholder="username" name="username" value="<?php echo set_value('username');?>" class="inputan" <?php echo form_error('username');?>> <br> <input type="password" placeholder="password" name="password" value="<?php echo set_value('password')?>" class="inputan" <?php echo form_error('username');?> ><br> <input type="button" value="login"> </div> <script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script> <?php form_close();?> </body> </html>

and .htaccess

options +followsymlinks options -indexes directoryindex index.php rewriteengine on rewritecond $1 !^(index\.php|images|styles|scripts|robots\.txt|favicon\.ico) rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ index.php?/$1 [l,qsa]

stuck few hours in problem.. wondering why changed hosting cause such problem.

thanks in advanced!

i had same problem in 1 of project.

i see problem in index function , login check status in login function.

you can refer below -

public function index($msg = null){ $this->is_logged_in(); //here i've added status check whether user logged in ['msg'] = $msg; $this->load->view('login_view', $data); } public function login(){ $this->load->model('login_model'); // validate user can login $result = $this->login_model->validate(); //validating user model // verify result if(! $result){ // if user did not validate, show them login page 1 time again $msg = '<font color=red>invalid username and/or password.</font><br />'; $this->index($msg); }else{ $this->redirect_other(); } } //end function login()

codeigniter loops redirect html-helper infinity

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -