Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:03+00:00 2026-05-26T15:52:03+00:00

I have a login function in my controller that was getting called before, but

  • 0

I have a login function in my controller that was getting called before, but i did some changes and it all just stopped.

I have a basic login with 2 inputs for a username/password and a submit

//Javascript

function initLogin(e) {
    e.preventDefault()
    var d = {
        user: $('#userName').val(),
        password: $('#password').val()
    }

    console.log('test')//gets returned

    $.post('/cms/login/',d,function(data) {
        console.log(data);//nothing returning
    },'json');
}

//Controller

class CMS extends CI_Controller {
    function __construct() {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('session');

        //$this->_check_if_logged_in();
    }

    private function _check_if_logged_in() {
        if (!$this->uri->segment(2) || $this->uri->segment(2) == 'login') return FALSE;
        if ($this->session->userdata('logged_in') != TRUE) redirect('/cms');
    }

    public function index() {
        if ($this->session->userdata('logged_in') == TRUE) redirect('/cms/home', 'refresh');

        $this->load->view('cms/log_in_view');
        $this->load->view('cms/parts/footer');
    }

    function login() {
        echo json_encode(array('test' => 'test'))//doesn't get echoed

        $data['user_name'] = $this->input->post('user');
        $data['pass_word'] = sha1($this->input->post('password'));

        $this->db->select('id');
        $res = $this->db->get_where('login',$data,1)->row_array();

        if (is_numeric($res['id'])) {
            $data['logged_in'] = TRUE;
            $this->session->set_userdata('logged_in',TRUE);
        }

        echo json_encode($res);
    }
}

Basically i commented out everything that I thought might get in the way of returning a response, but this is going against everything I’ve learned.

I’m convinced the login function in the controller doesn’t get called, even though it did before when i didn’t change anything in the js or login function itself

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:52:03+00:00Added an answer on May 26, 2026 at 3:52 pm

    One flaw I see is that if you find no row, $res['id'] will make codeigniter print out a HTML error, which makes your json echo not work properly.

    Try if (!empty($res)) instead.

    You can check with the Firebug Console (Addon in Firefox) what the ajax-request gave for an answer to see if more then the json was echo’d.

    Edit:

    Noticed that’s not the real problem. Will read it again.

    Try changing class CMS extends CI_Controller to class Cms extends CI_Controller

    That is CMS -> Cms

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm Using CakePHPs standard Auth mechanism, but I have some problems with that. Everytime
I'm creating a login form with Codeigniter, and I have a controller that collects
I have a CI app that has a auth controller and switchuser function. Basically
I have a user controller that checks to login a user. It has this
I have a application/controller/login.php file containing the following class Login extends Controller { function
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
I have two functions that have different enough logic but pretty much the same
Hi I want to create a WCF service that have login method, which is
Basically, I currently have login/ in urls.py redirect to the django.contrib.auth.views.login and that seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.