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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:12:11+00:00 2026-05-24T14:12:11+00:00

I have a user controller that checks to login a user. It has this

  • 0

I have a user controller that checks to login a user. It has this snippet of code. I can set set_userdata and echo it in my view, but this doesnt work for my flash data as shown below.

 public function login()
    {
        if($this->input->post('submit_login'))
        {
            // Get Posted Vars
            $username = $this->input->post('username');
            $password  = md5($this->input->post('password'));

            // Run query to return 1 result if TRUE
            $query = $this->user_model->check_login($username, $password);

            if ($query == FALSE)
            {
                $this->session->set_flashdata('flashdata', 'Incorrect Username or Password doesnt show');
                $this->session->set_userdata('userdata', 'userdata works');
                // Query was wrong, set flash data and redirect to login
                $data['main_content'] = "user/login";
                $data['title'] = "Login";
                $this->load->view('template', $data);
            }
            else // Else Query returned 1 item
            {
                // Get the Variables
                $user_id = $query->row(0)->id;
                $username = $query->row(0)->username;
                $user_email = $query->row(0)->email;
                $user_type = $query->row(0)->type;

                // Load up the userdata array
                $userdata = array(
                    'logged_in' => TRUE,
                    'user_id' => $user_id,
                    'username' => $username,
                    'user_email' => $user_email,
                    'user_type' => $user_type
                    );

                // Execute the set_userdata, to our session
                $this->session->set_userdata($userdata);

                $data['main_content'] = "Admin/index";
                $data['title'] = "Administrator";
                $this->load->view('template', $data);
            }
        }
        elseif ($this->session->userdata('logged_in') == TRUE)
        {
            $this->index();
        }
        else
        {
                $data['main_content'] = "user/login";
                $data['title'] = "Login";
                $this->load->view('template', $data);
        }

Then in my view:

<form action="<?php echo base_url(); ?>user/login" method="POST" id="login_form"/>
<p>Please Login Below</p>
<span class="notice"><?php echo $this->session->flashdata('flashdata'); ?></span>
<span class="label">Username:</span><input type="text" name="username"/><br/>
<span class="label">Password:</span><input type="password" name="password"/><br/>
<input type="submit" name="submit_login" value="Login"/>
</form>
<?php echo $this->session->flashdata('flashdata'); ?>
<br/>
<?php echo $this->session->userdata('userdata'); ?>

Why doesnt flashdata show?

  • 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-24T14:12:13+00:00Added an answer on May 24, 2026 at 2:12 pm

    flashdata in codeigniter only exists in the session for one additional request and then is destroyed. If you are inadvertently trying to use it past a single request, it will not exist by the time you try and access it. userdata though exists as long as the session exists.

    UPDATE

    After looking at more of your code, it looks like this happens because you’re not actually redirecting (creating the next request) here, you’re just loading a view…

            if ($query == FALSE)
            {
                $this->session->set_flashdata('flashdata', 'Incorrect Username or Password doesnt show');
                $this->session->set_userdata('userdata', 'userdata works');
                // Query was wrong, set flash data and redirect to login
                $data['main_content'] = "user/login";
                $data['title'] = "Login";
                $this->load->view('template', $data);  //<---- See?
            }
    

    Instead do this…

            if ($query == FALSE)
            {
                $this->session->set_flashdata('flashdata', 'Incorrect Username or Password doesnt show');
                $this->session->set_userdata('userdata', 'userdata works');
                // Query was wrong, set flash data and redirect to login
                redirect("uri/path/to/login");
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I'm writing an iPhone program that has a login view controller that allows the
I have this controller set up for a login: <?php class Login extends Controller
I am using the Zend Framework. I have a controller named 'UserController' that has
I have a controller user with a method login For some reason, when I
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I'm creating a login form with Codeigniter, and I have a controller that collects
I have a check_user_access_control before_filter in my ApplicationController that checks the logged user's roles
I am trying to code my first codeigniter project. I have a login controller
I have persistent login in my website so if user checks the remember me

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.