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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:50:03+00:00 2026-05-29T19:50:03+00:00

I have create a web application using CodeIgniter making at first a login interface.

  • 0

I have create a web application using CodeIgniter making at first a login interface. Here are the controller I used but I think something doesn’t work but I don’t know what.The home page, where the user is granted, it doesn’t show.Unfortunately I didn’t have a debugger to check what doesn’t work. maybe there is a problem to handle the session but really I don’t know what can be. maybe you are smarther than me to find the error


Login Controller

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

class Login extends CI_Controller 
{
    public function __construct() 
    {
        parent::__construct();
        $this->load->model('User','user'); /* This call the model to retrieve data from db */
    }

    public function index()
    {
        if(!file_exists('application/views/_login.php'))
        {
            show_404();
        }

        $this->load->library('form_validation');

        $this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>');

        $this->form_validation->set_rules('username','username','trim|required|xss_clean');
        $this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check');

        if($this->form_validation->run() == FALSE)
        {
            /* Data to pass to view */
            $data['title'] = "User Access";
            $data['author'] = "Salvatore Mazzarino";
            $data['year'] = date('Y');

            $this->load->view('templates/_header',$data);
            $this->load->view('_login',$data);
            $this->load->view('templates/_footer',$data);
        }
        else 
        {   
            redirect('home', 'refresh');            
        }
    }

    public function pass_check($pass)
    {
        $result = $this->user->find_user($this->input->post('username'),$pass);

        if(!empty($result))
        {
            foreach ($result as $row) 
            {
                $session_array = array('id'=> $row->id, 'username'=> $row->username); /* Create a session passing user data */

                $this->session->set_userdata('logged_in', $session_array);
            }
            return TRUE;
        }
        else
        {
            $this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!");
            return FALSE;
        }
    }
}

/* END OF FILE */

Home Controller

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


class Home extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        session_start();
    }

    public function index()
    {
        if($this->session->userdata('logged_in'))
        {            
            $data['title'] = "Management Emergency";
            $data['author'] = "Salvatore Mazzarino";
            $data['year'] = date('Y');

            $this->load->view('templates/_header', $data);
            $this->load->view('_home',$data);
            $this->load->view('templates/_footer',$data);
        }
        else
        {
            redirect('login', 'refresh');
        }
    }

    public function logout()
    {
        $this->session->unset_userdata('logged_in');
        session_destroy();
        redirect('home','refresh');
    }
}

/* END OF FILE */

The model in the login controller works very well so It isn’t a problem of query. Before adding session everything works but when I added session stopped to worked so I think that can be a problem or redirect() or session

Home View

<div data-role = "page">

<div data-role = "header" data-position = "inline">
        <a href="" data-icon = "home" data-iconpos = "notext"></a>
            <?php echo heading($title,1) ?>
        <a href="" data-icon = "info" data-iconpos = "notext" data-transition= "flip"></a>
</div>

<div class = "menu-content">
        <ul data-role = "listview" data-inset="true">
                <li data-role = "list-divider">Emergency Menù</li>
                <li class = "menu-item">
                        <a href="">
                                <div class = "image-wrapper">
                                        <img src="/assets/images/user.png" class = "ui-li-icons" />
                                </div>
                                Add patient
                        </a>
                </li>
                <li class = "menu-item">
                        <a href="#">
                                <div class = "image-wrapper">
                                        <img src="/assets/images/home.png" class = "ui-li-icons" />
                                </div>
                                Show all hospital
                        </a>
                </li>
                <li class = "menu-item">
                        <a href="#">
                                <div class = "image-wrapper">
                                        <img src="/assets/images/favorite.png" class="ui-li-icons" />
                                </div>
                                Find patients
                        </a>
                </li>
                <li class="menu-item">
                        <a href="#">
                                <div class = "image-wrapper">
                                        <img src="/assets/images/email.png" class="ui-li-icons" />
                                </div>
                                Send medical infos
                        </a>
                </li>
        </ul>

Login View

<div data-role ="dialog">

<div data-role = "header" data-theme="e">
    <?php echo heading($title,1) ?>
</div>

<div data-role ="content">

    <?php 

        $var = validation_errors();

        if(!empty($var))
        {
            echo form_error('username');
            echo form_error('password');
        }
        else
        {                    
                echo heading('911 - First Aid',2,'style="text-align:center; color:red;"');

                echo form_open('login');
    ?>
                    <div data-role ="fieldcontain" class="ui-hide-label">
                        <label for="username">Username:</label>
                        <input type="text" name="username" id="name" value="" placeholder="Username"/>
                    </div>

                    <div data-role ="fieldcontain" class="ui-hide-label">
                        <label for="password">Password</label>
                        <input type="password" name="password" id="password" value="" placeholder="Password"/>
                    </div>

                    <div data-role ="fieldcontain">
                        <input type="submit" value="Login" data-theme ="b"/>
                    </div>

                </form>

   <?
        }
   ?>
  • 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-29T19:50:04+00:00Added an answer on May 29, 2026 at 7:50 pm

    There is a problem with CodeIgniter retaining it’s session data after a redirect. Your if($this->session->userdata('logged_in')) in your home.php controller will evaluate false every time because the session is resetting. You could use the native php sessions to skip over this problem.

    See: http://codeigniter.com/wiki/Native_session/. Good luck!

    UPDATE

    Apparently, this is only true of CodeIgniter 1.7.2 when used with IE6. It doesn’t affect most browsers.

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

Sidebar

Related Questions

I am using the webapplicationbuilder class to create a new web application and have
I'm using Rational Application Developer to create some web services. The problem I have
Normally I create web application projects and use code-behind, but I have a requirement
I have just create a very basic Dynamic Data web application using Entity Framework,
I have web application in that i am using tabbed interface control in this
I'm developping a web application using google appengine and django, but I think my
I am trying to create a login system for a web application, but I
I have created a web application using Visualstudio 2008 using C# on my computer.
We have created a web application, using ASP.NET, that allows users to upload documents
I have created a web application with a Silverlight project embedded in it, using

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.