treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Php Headers already sent... What should i do?

  • hey i have a multilingual cms plugin running on my wordpress site.

    Apparently when i try to add a php header function to my code, the server responds with an error saying that my headers were already sent out because of this plugin.

    I have exclusive content on my site in which only people with a certain level of access can view. By default if a person tries to view that content without the right credentials, they automatically get sent over to my free subscription form. The thing is that if a subscriber (that is already logged in) tries to view a page that they don't have access to they are still getting sent to the free subscription page even though they are already subscribers.

    What im trying to accomplish is this,



    <?php if(is_user_logged_in()){ ?>
    <?php header('Location: http://tpanalysis.com/?page_id=443'); ?>
    <?php } else { ?>
    [s2Member-Pro-PayPal-Form register="1" level="0" ccaps="" desc="Signup now, it's Free!" custom="tpanalysis.com" tp="0" tt="D" captcha="clean" /]
    <?php } ?>


    P.S- Sorry for the php mess:P
  • That's because something has already been sent to the client-side. I think...

    Use this function instead: http://codex.wordpress.org/Function_Reference/wp_redirect
  • Warning: Cannot modify header information - headers already sent by (output started at /home/kmarimon/public_html/tpanalysis.com/wp-content/plugins/sitepress-multilingual-cms/inc/language-switcher.php:716) in /home/kmarimon/public_html/tpanalysis.com/wp-includes/pluggable.php on line 897


    thats the error i get when i include the wp_redirect function
  • is there any code that comes before that command that outputs anything to the page? the header statement won't work unless nothing has been sent to the browser all ready. One way you could do it is to use javascript to redirect the user.