Search code examples
phpcodeignitersessionhttp-redirectcodeigniter-4

In CodeIgniter 4 Flashdata displaying code redirecting to again again in the same page


In the CodeIgniter 4, I am using Flashdata for displaying error or success messages in view page and I am using the below code:

<?php
    if(session()->get("success")){
        echo session()->get("success");
    }
?>

It is not and as well as it redirect frequent in same page using this code!


Solution

  • use Flashdata instead of session.

    Once you reload the page, flashdata will disappear

    $session->setFlashdata('item', 'value');
    # to rerive
    $session->getFlashdata('item');
    

    You can warp it with if conditions well.

    if($session->getFlashdata('item')){}
    

    Read more Flashdata - in codeigniter.com