tags:

views:

52

answers:

3

i have situation where i create solution. I use wordpress and unfortunetly, i have to work behind the backend. I need to print message about user action while the CMS header have been sent. Is there any alternative then using javascript :

echo '<script type="text/javascript">/* <![CDATA[ */'; 
echo 'window.location.href = "'. $redirect_url . '";'; 
echo '/* ]]> */</script>';

i prefere a php solution.

+1  A: 

You can pass the message by using query string:

header('location: index.php?msg=1');exit;

And use swich to show the message based on value of msg query string var:

switch($_GET['msg'])
{
   case: 1; // do foo
   case: 2; // do bar
   case else : ; // ooops
}
Mike Johnson
He said after the header has been sent... I presume he meant once the content has been started - php will complain if you try send a header again
gordonml
+1  A: 

You can't undo that header sending ... but you can buffer it, which is what I ended up doing when I asked this question.

Hope that helps

LeonixSolutions
from behind of that noted "backend"?
Col. Shrapnel
A: 

I prefer:

1.) place config.php to load at the top of every page and put ob_start in it

2.) place end_load.php to load at the end of every page and put the ob_end in it

this way will ensure no output is given to client till the end of processing and you can use header redirect at any time of page.

i am ignorant of disadvantages of it. May be caching has disadvantage but not sure

KoolKabin
@downvoter: plz write something as i can also know why its not good
KoolKabin
I voted you back up (not down) it seems fine to me.
LeonixSolutions