Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter session work fine on local but not working on Godaddy [closed]

Tags:

codeigniter

I developed website on php framework (Codeigniter) that working fine on my local (WAMP Server). When I upload it to Godaddy hosting, it unable to login into website. Below is the login class function.

public function index()
{

    if ($this->session->userdata('admin_login') == 1)
        redirect(base_url() . 'index.php?admin/dashboard', 'refresh');


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


function ajax()
{
    $response = array();


    $email      = $_POST["email"];
    $password   = $_POST["password"];
    $response['submitted_data'] = $_POST;       


    $login_status = $this->validate_login( $email ,  sha1($password) );
    $response['login_status'] = $login_status;
    if ($login_status == 'success') {
        $response['redirect_url'] = '';
    }

    echo json_encode($response);
}


function validate_login($email  =   '' , $password   =  '')
{
    $credential =   array(  'email' => $email , 'password' => $password );

    $query = $this->db->get_where('users' , $credential);

    if ($query->num_rows() > 0) {
        $row = $query->row();
          $this->session->set_userdata('admin_login', '1');
          $this->session->set_userdata('admin_id', $row->id);
          $this->session->set_userdata('name', $row->name);
          $this->session->set_userdata('login_type', 'admin');

          return 'success';
    }

    return 'invalid';
}

I realize that $this->session->set_userdata() method is not working on godaddy.

like image 840
bravo Avatar asked Nov 01 '14 10:11

bravo


3 Answers

Please try this 
Please add  session library  just like below.

$this->load->library('session');
if ($this->session->userdata('admin_login') == 1)
        redirect(base_url() . 'index.php?admin/dashboard', 'refresh');



     $this->load->view('backend/login');
like image 196
sujeet gupta Avatar answered Oct 28 '22 04:10

sujeet gupta


First Load Session Library then Instead of Using this

  if ($this->session->userdata('admin_login') == 1)

Use This

if ($this->session->userdata['admin_login'] == 1)

Check if it is working or not

like image 2
Abhijit Mali Avatar answered Oct 28 '22 05:10

Abhijit Mali


Try a few alternatives may work: Change these lines in application/config/config.php

$config['sess_cookie_name'] = 'cisession';     //remove(underscore)
$config['cookie_domain']    = ".example.com";  //make it site wide valid
like image 1
Keval Rathi Avatar answered Oct 28 '22 03:10

Keval Rathi