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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:20:15+00:00 2026-06-12T16:20:15+00:00

I am currently building a website with codeigniter 2.1.2. Now I am encountering a

  • 0

I am currently building a website with codeigniter 2.1.2. Now I am encountering a problem to efficiently building a multi-language website.

I have read through the language class tutorial and helper and I have stored two language folders “Chinese” and “English”.

What I am intending to do is I want a language session variable called “lang”. And I want the following:

  1. if no session variable “lang” exists, I will create one and point it to “english”
  2. if the session variable is already set and user clicked for a change of language, then the session variable will change from either “chinese” to “english” or “english” to “chinese”.

I am quite new to PHP and Codeigniter, All I can think of now is something like the following. Can anyone shine some light as of how I can efficiently allow users to change language on my site?

I have no idea how to change session variable upon user’s click event.

// Load Language Files 
if(!$this->session->userdata('lang')) {
    $this->session->set_userdata('lang','english');
    $lang = 'english';
} else {
    $lang = 'chinese';
}
$this->lang->load('pages/header',$lang);

I have created a language controller and set the session variable, and then redirect the page back to the previous page. Is it a good way?

  <?php

Class language Extends CI_Controller {

    function index() {
        if(!$this->session->userdata('lang')) {
            $this->session->set_userdata('lang','english');
        } else {
            $lang = $this->session->userdata('lang');
            if ($lang =="chinese") {
                $this->session->set_userdata('lang','english');
            } elseif ($lang == "english") {
                $this->session->set_userdata('lang','chinese');
            } else {
                $this->session->set_userdata('lang','english');
            }
        }
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
}
  • 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-06-12T16:20:17+00:00Added an answer on June 12, 2026 at 4:20 pm

    make a language controller. Direct a user to relevant method when user click language link
    http://www.yoursite.com/language/english for English language and similar for chinese. I have used cookie instead of session variables.

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Language extends CI_Controller{
        function __construct(){
            parent::__construct();
        }
    
        public function index(){
            $this->english();
        }
    
        public function english(){
            $this->lang->load('labels', 'english');
            //$this->session->set_userdata("LANGUAGE","english");
            $cookie = array(
                        'name'   => 'LANGUAGE',
                        'value'  => 'english',
                        'expire' => 604800
                    );
            $this->input->set_cookie($cookie);
            header("location: ".$_GET["ref"]);
        }
    
        public function chinese(){
            $this->lang->load('labels', 'chinese');
            //$this->session->set_userdata("LANGUAGE","chinese");
            $cookie = array(
                        'name'   => 'LANGUAGE',
                        'value'  => 'chinese',
                        'expire' => 604800
                    );
            $this->input->set_cookie($cookie);
            header("location: ".$_GET["ref"]);
        }
    
    }
    
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a job-board website with CodeIgniter 2.0 that is very user content
I am currently building a website in codeigniter that is one page site, basically
I'm building a website using MVC3, EF, and Razor and I currently have the
i'm currently building a new private website and now it's time for building the
I'm currently building a website with Django and want to host user bio style
I'm currently building a website (ASP.net c#) and we're looking at creating a live
I am currently building an making my new website. It uses one page and
i am currently building a custom shopping cart to my website, it has all
I am a noob in ASP.NET and building a website currently... I want the
I am currently building a website for a client, and am experiencing an issue

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.