• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot modify header

#1
[eluser]fuji2009[/eluser]
Hello i don t understand, i want create an alert just before redirect my page so i try this :


Code:
function desinscrire($event_id){
        $this->load->model('evenement_model');
        $user_login_id = $this->session->userdata('id');
        $this->evenement_model->desinscription_events($user_login_id,$event_id);
        $this->evenement_model->desinscription_valid_events($user_login_id,$event_id);
        echo"[removed]alert('ok')[removed]";
        redirect($_SERVER['HTTP_REFERER']);
    }

but i have this error :

Code:
A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/lovemeet/www/siteweb/application/controllers/evenements.php:746)

Filename: helpers/url_helper.php

Line Number: 565

Code:
ligne 746 is : echo"[removed]alert('ok')[removed]";

Why don t work ?


[removed] = < script > without space
Thank you

#2
[eluser]Twisted1919[/eluser]
redirect() function uses php's header() function for redirect.
in order for header() to work properly, nothing needs to be echo before it is called, else, you will get an error, like you did .

Read more about header() and you will get the point .

#3
[eluser]fuji2009[/eluser]
ok thanks i understand, so how can i do for create an alert JS before redirect my page ? thank you

#4
[eluser]Twisted1919[/eluser]
If i were you, i would use session->set_flashdata(); and add a variable there right before redirect, then after the redirect is done and the new page is loaded, do a check for the flashdata variable and if it is present, do the alert then .


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.