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 6897521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:10:44+00:00 2026-05-27T07:10:44+00:00

I am trying to integrate nodejs and nowjs with codeigniter framework, As I dont

  • 0

I am trying to integrate nodejs and nowjs with codeigniter framework, As I dont have time to rewrite the whole site I want to check if a user is logged in. I am using ion_auth and I am storing the session in db.

Client js:

var session_id = $.cookie('sc_session');

$("form").submit(function() {
    now.distributeMessage($("textarea").val(),session_id);
});

now.receiveMessage = function(message){
    $("body").append("<br>" + message);
};

Heres the nodejs server code:

EDIT:*Simplified it a little, and get session cookie from client js*

everyone.now.distributeMessage = function(message,session_cookie) {
    exec('php index.php user_session decrypt ' + encodeURIComponent(session_cookie),
    function (error, stdout, stderr) {
        var parts = stdout.split(';');
        var session_id = parts[1].split(':')[2];
        var query = 'select * from sc_sessions where session_id=' + session_id;
        client.query(query, function (err, results, fields) {
            if (results) {
                everyone.now.receiveMessage(str);
            }
        });
    });
};

And here is the controller called by nodejs:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class User_session extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
    if (!$this->input->is_cli_request()) {
        redirect('index');
    }
  }

  public function decrypt($session_id)
  {
    $this->load->library('encrypt');
    $session_id = urldecode($session_id);
    echo $this->encrypt->decode($session_id);
  }
}

It is working and i can log the user_data to the console from the session in database, and it calls the everyone.now.receiveMessage function properly.

I have three questions regarding this:

1) there are rows inserted into the sc_sessions db table with a session_id but with empty user_data, user_agent and ip 0.0.0.0. One row each time the form is submitted.

What is causing this and how do i fix it?

I know that there is a problem with ajaxcalls and codeigniter sessions. See this thread:

Is there a way to see if the request was made with websockets?

2) What is the best way to check if the user is logged in? e.g if statement where you check to see if the query returned anything or is there a better method?

3) Is there a better method of doing this?

Any help appreciated as I am stuck on this.

George

EDIT:
Calling the script from commandline caused it to create a new session. Prevent it by extending the session class.

application/libraries/MY_Session.php

<?php
class MY_Session extends CI_Session {

    public function __construct()
    {
        $CI = get_instance();

        if ($CI->input->is_cli_request())
        {
             return;
        }

        parent::__construct();
    }  
}
  • 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-27T07:10:45+00:00Added an answer on May 27, 2026 at 7:10 am

    Great question, but lots of overhead to test an answer.

    My best guess is CLI doesn’t pass environmental variables like user_agent and ip. Those are handled by apache, and aren’t relevant in CLI requests natively. I’d go by session_id alone if you know it’s secure in a node environment.

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

Sidebar

Related Questions

While trying to integrate Yahoo Media Player into my own website, I want to
I'm trying to integrate a public message board service into an existing web site.
I'm trying to integrate some photo related functionality with my site and facebook. I
I am trying to integrate a Hibernate application into a proprietary framework. My problem
I have been trying to figure out how to integrate a node.js app into
Im trying to integrate FBConnect to my application and want to know if the
I'm trying to integrate a javascript called ImageFlow into a Joomla site, but I'm
I'm trying to integrate twitter in iOS5 app. Using Twitter framework in my app,
Trying to integrate some friendly_id gem functionality on a controller method. Essentially, I have
I'm trying to integrate running Fitnesse tests from MSBuild im my nightly build on

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.