2014-11-04 125 views
0

後,我改變了我的笨文件和屏幕有這樣重定向循環的笨

http://webdomain.com/index.php/login/login diplay錯誤了過多的重定向導致 。清除您的本網站的Cookie或允許第三方Cookie可以解決此問題。如果沒有,可能是 服務器配置問題,而不是您的計算機的問題。瞭解更多關於此問題的 。錯誤代碼:ERR_TOO_MANY_REDIRECTS

它可能會被無限循環重定向導致我試圖修復了幾個小時,我不問題出在哪裏有我的代碼,但我不能弄清楚什麼在我的代碼和我的錯誤使用谷歌瀏覽器的瀏覽器

我的路線默認控制器是index.php文件

這裏是login.php中(控制器)代碼

<?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() as $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'); 
} 
} 

?> 

這裏是login_model.php(M奧德爾)代碼

<?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(); 
     return $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'); 
     return $query->row(); 
    } 
} 
?> 

,這裏是視圖login_admin.php代碼

<!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 Something 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> 

,然後這個的.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] 

在這個問題上卡住了幾個小時..我也想知道爲什麼改變主機導致這樣的問題。

感謝先進!

回答

0

我在我的一個項目中遇到了同樣的問題。

我看到問題出現在登錄函數的索引函數和登錄檢查條件中。

您可以參考以下 -

public function index($msg = NULL){ 
    $this->is_logged_in(); //here i've added the condition to check whether user is logged in 
    ['msg'] = $msg; 
    $this->load->view('login_view', $data); 
} 

public function login(){ 
    $this->load->model('login_model'); 
    // Validate the user can login 
    $result = $this->login_model->validate(); //validating the user into model 

    // 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{    
      $this->redirect_other(); 
    }   
} //end function login() 
0

只是刪除第一個被記錄在您的登錄功能檢查,就像你說的默認功能是在你調用登錄/註冊指數。你不需要再次重演它。