Cannot get flash data to work to a page after register

Asked
Active3 hr before
Viewed126 times

5 Answers

cannot
90%

Meta Stack Overflow , Stack Overflow Public questions & answers ,So I am trying to get from login screen to admin screen, and I set flash data so I can tell the users if they are logged in, and also check if there is more than one user or a wrong password it will show sorry you are not logged in. So this is my controller., Stack Overflow help chat

After setting flash data redirect the page

redirect('controllerNmae/Method');

In view

< ? php
if (!empty($this - > session - > flashdata('login_sucess'))) {
   echo $this - > session - > flashdata('login_sucess');
}

if (!empty($this - > session - > flashdata('login_failed'))) {
   echo $this - > session - > flashdata('login_failed');
} ?
>

or

<?php
    if(!empty($this->session->flashdata('login_sucess')))
    {
        ?>
        <script>
            alert('<?php $this->session->flashdata('login_sucess'); ?>');
        </script>
    <?
    }

     if(!empty($this->session->flashdata('login_failed')))
    {
        ?>
        <script>
            alert('<?php $this->session->flashdata('login_failed'); ?>');
        </script>
    <?
    }
?>

Tip: Use this library alertify JS. Its gives nice user experience
Ex

<script>
   alertify.success('<?php $this->session->flashdata('
      login_sucess '); ?>');
</script>
load more v
88%

Flashdata can be retrieved using the flashdata() function which takes one argument of the item to be fetched as shown below. flashdata() function makes sure that you are getting only flash data and not any other data.,If you do not pass any argument, then you can get an array with the same function.,mark_as_flash() function is used for this purpose, which takes only one argument of the value to be stored. We can also pass an array to store multiple values.,CodeIgniter - Flashdata

We can simply store flashdata as shown below.

$this - > session - > mark_as_flash('item');
load more v
72%

simlpe code doesn’t show any flashdata,Try this profiler extension to check if your session data is actually being set properly,Also, why are you calling session_start? People tend to get wierd problems mixing native and CI sessions,One example is trying ot set flashdata, the other userdata.  does flashdata support arrays?

class Main extends Controller {

   function __construct() {
      parent::Controller();
      include('sys/_jobs/views/inc/common.inc.php');
      session_start();
      $this - > output - > enable_profiler(TRUE);
   }

   function test() {
      $this - > session - > set_flashdata('item', 'test');
      $this - > load - > view('test');
   }
load more v
65%

A mechanism for self-identification (comparable to the serial presence detection feature of SDRAM memory modules),Solid-state computer storage media,The floating gate may be conductive (typically polysilicon in most kinds of flash memory) or non-conductive (as in SONOS flash memory).[55] ,9.2 Flash memory as a replacement for hard drives

75%

In this section, you will learn about sending flash messages to other pages using the session library in CodeIgniter,Sending Flash Messages to other pages with CI Sessions ,CodeIgniter Session Management ,$route[‘authenticate’] = ‘sessioncontroller/authenticate’; defines the route that simulates successful user login and sets the session login data.

Create a new file SessionController in

application / controllers / SessionController.php
load more v

Other "cannot-undefined" queries related to "Cannot get flash data to work to a page after register"