Welcome Guest, Not a member yet? Register   Sign In
Whats wrong with this code?
#1

[eluser]phpfresher[/eluser]
Note :-Please this is not a design problem
Problem:Below code works fine for mozilla . But in IE page redirects to the login page without any message.
Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
var $data = array();
function __construct(){
   parent::__construct();
   $this->load->model('login_model');
   $this->load->model('user_model');
   $this->load->model('setting_model');
   //$this->data['permission'] = $this->user_model->getpermission();
   $this->data['modules']    = $this->setting_model->listofmodules();
  
  

}
    
  function index()
{

  if(!($this->session->userdata('user_name'))){
   redirect($this->config->item('admin_url').'/home/login');
  
   }
  redirect($this->config->item('admin_url').'/home/main');
}

function main(){
  
  $this->data['template'] = $this->config->item('admin_url').'/default';
  $this->load->view($this->config->item('admin_url').'/main',$this->data);
}

function login(){
  $data = array();
  if($this->input->post('submit')){
   $username = $this->input->post('username',TRUE);
   $password = $this->prepare_password($this->input->post('password',TRUE));
   $logincheck = $this->login_model->login_check($username,$password);
  
   if($logincheck == 'Yes'){
    $this->session->set_userdata('user_name',$username);
    $this->session->set_userdata('user_id',get_login_id($username,$password));
       redirect($this->config->item('admin_url').'/home');
   }
   $data['message']  = $logincheck;
  }
  $this->load->view($this->config->item('admin_url').'/login',$data);
}

   function prepare_password($password){
    return sha1($password.$this->config->item('encryption_key'));
   }
  
   function logout(){
   $this->session->unset_userdata('user_name');
    $this->session->unset_userdata('user_id');
     $this->session->unset_userdata('group_id');
   redirect($this->config->item('admin_url').'/home');
   }
  
  }
//End of validation function

MODEL:
Code:
<?php
class Login_model extends CI_Model{
     function __construct(){
  
}
function index(){
  parent::__construct();
}

function login_check($username,$password){
  $query = $this->db->query("select * from tbl_user where username='$username' and password='$password' and status='1'");
  $num  = $query->num_rows();
   if($num>0){
     foreach($query->result() as $output ){
       $groupstatus   = getgroupstatus($output->gid);
      
        switch($groupstatus){
          case '34':
             return 'Yes';
             break;
           case '45' :
           return 'Sorry ,You Have Been Blocked';
           break;
          default :
             return 'Yes';  
                
       }
       }
    
   }else{
     return 'Wrong Username or Password';
   }
  
}

}


?>

VIEW:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;

&lt;title&gt;LOGIN:.&lt;/title&gt;
&lt;meta name="description" content="How to build a slick CSS3 Login Form with no images."&gt;
&lt;style type="text/css"&gt;
* {
  margin: 0px;
  padding: 0px;outline: none;
}

body {
  background: #4E0085;
}

form {
  border: 1px solid #270644;
  width: 250px;
  -moz-border-radius: 20px;
  -webkit-border-radius: 20px;
  background:  -moz-linear-gradient(19% 75% 90deg,#4E0085, #963AD6);
  background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#963AD6), to(#4E0085));
  margin:50px auto;
  padding: 20px;
  -moz-box-shadow:0px -5px 300px #270644;
  -webkit-box-shadow:0px -5px 300px #270644;
}

label {
  font-size: 12px;
  font-family: arial, sans-serif;
  list-style-type: none;
  color: #fff;
  text-shadow: #000 1px 1px;
  margin-bottom: 10px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: block;
}

input {
   -webkit-transition-property: -webkit-box-shadow, background;
   -webkit-transition-duration: 0.25s;
    padding: 6px;
  border-bottom: 0px;
  border-left: 0px;
  border-right: 0px;
  border-top: 1px solid #ad64e0;
  -moz-box-shadow: 0px 0px 2px #000;
  -webkit-box-shadow: 0px 0px 2px #000;
  margin-bottom: 10px;
  background: #8a33c6;
  width: 230px;
}

input.submit {
   -webkit-transition-property: -webkit-box-shadow, background;
   -webkit-transition-duration: 0.25s;
  width: 100px;
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#963AD6), to(#781bb9));
  background:  -moz-linear-gradient(19% 75% 90deg,#781bb9, #963AD6);
  color: #fff;
  text-transform: uppercase;
  text-shadow: #000 1px 1px;
  border-top: 1px solid #ad64e0;
  margin-top: 10px;
}

input.submit:hover {
  -webkit-box-shadow: 0px 0px 2px #000;
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#963AD6), to(#781bb9));
  background:  -moz-linear-gradient(19% 75% 90deg,#781bb9, #963AD6);
}

input.submit:active {
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#781bb9), to(#963AD6));
  background:  -moz-linear-gradient(19% 75% 90deg,#963AD6, #781bb9);
}

input:hover {
  -webkit-box-shadow: 0px 0px 4px #000;
  background: #9d39e1;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="&lt;?php echo base_url();?&gt;login/login_user" method="post"&gt;

  <label>Username:</label>
   &lt;input type="text" name="username" /&gt;
  <label>Password:</label>
   &lt;input type="password" name="password"  /&gt;
   &lt;input type="submit" value="Submit" name="submit" class="submit" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;


This code is fine for mozilla ie. redirects to the specified page . But in IE redirects back to the page login page .
#2

[eluser]InsiteFX[/eluser]
And that should tell you that you have an IE Session problem!

In the config.php file remove the underscore in ci_cession of the cookie name!
#3

[eluser]phpfresher[/eluser]
Thanks , it solved may problem. Can you tell how and why this solution worked
#4

[eluser]Aken[/eluser]
Internet Explorer doesn't allow underscores in cookie names. http://support.microsoft.com/kb/316112
#5

[eluser]phpfresher[/eluser]
Sorry dude , again i am having the same problem again in some PCs , The same code works fine in some PCs but donot work on some PCs i.e the login works fine in my PC but donot work on the clients PC but i have tested the code 5 PC where in 2 Computer the logins redirect to the login page.




Theme © iAndrew 2016 - Forum software by © MyBB