I use this for flash data and it's easy to use. first, need to you have create session and then in your controllers' method use this just before where you want to redirect your page.
On Controller after creating a session and don't forget to load session and url library.
$this->session->set_flashdata('success', 'Oops. This email id already exist.');
redirect("Your method or page");
In this case, you no need to add any extra php code in your particular view page.Just copy and paste this below script in your footer.php.Good luck and hope it will help for your problem.
<!-- Code for flashdata toaster --> <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css"> <script type="text/javascript"> <?php if($this->session->flashdata('success')){ ?> toastr.success("<?php echo $this->session->flashdata('success'); ?>"); <?php }else if($this->session->flashdata('error')){ ?> toastr.error("<?php echo $this->session->flashdata('error'); ?>"); <?php }else if($this->session->flashdata('warning')){ ?> toastr.warning("<?php echo $this->session->flashdata('warning'); ?>"); <?php }else if($this->session->flashdata('info')){ ?> toastr.info("<?php echo $this->session->flashdata('info'); ?>"); <?php } ?> </script> <!-- End of flashdata script -->