what is this error and what would i do to fix it?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Seraphimk
Forum Newbie
Posts: 22
Joined: Mon Feb 09, 2009 12:49 pm

what is this error and what would i do to fix it?

Post by Seraphimk »

Warning: Cannot modify header information - headers already sent by (output started at /home/virtualb/public_html/msm/registration/index.php:4) in /home/virtualb/public_html/msm/registration/index.php on line 152
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: what is this error and what would i do to fix it?

Post by requinix »

It's telling you that you tried to use header() after outputting something.

The solution is to fix your code so that doesn't happen.
Seraphimk
Forum Newbie
Posts: 22
Joined: Mon Feb 09, 2009 12:49 pm

Re: what is this error and what would i do to fix it?

Post by Seraphimk »

so would i have to look earlier on in the script to see if i ve used the header () function?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: what is this error and what would i do to fix it?

Post by Apollo »

Seraphimk wrote:so would i have to look earlier on in the script to see if i ve used the header () function?
No, you have to look earlier in the script before the failing header() function, for something like print or echo, or anything else that outputs (i.e. generates HTML) before sending that header.
Seraphimk
Forum Newbie
Posts: 22
Joined: Mon Feb 09, 2009 12:49 pm

Re: what is this error and what would i do to fix it?

Post by Seraphimk »

Ive looked through my script and i cant find anything wrong ill paste the script up till the error and see if you find anything.!

Code: Select all

 
<?php
 
    require_once('../lib/config.php');
    require_once('Smarty.class.php');
    require_once('Forms.class.php');
    require_once('Functions.class.php');
    require_once('Error.class.php');
    require_once('User.class.php');
    require_once('Mailer.class.php');
    require_once('Utils.class.php');
    require_once('HtPasswd.class.php');
 
    if(!isset($_REQUEST['action'])){
        $_REQUEST['action']='regform';
    }
 
    switch ($_REQUEST['action']){
 
        case 'edit':
            require_once('auth_db.php');
            $ht = new HtPasswd( SITE_DOC_ROOT . '/members/.htpasswd');
            $user_id = User::idFromEmail($_SERVER['PHP_AUTH_USER']);
            $user = new User($user_id);
            $smarty = new Smarty();
            $smarty->compile_dir = SITE_DOC_ROOT . '/templates_c';
            $smarty->assign('user', $user);
            $smarty->assign('has_access', $ht->isUser($_SERVER['PHP_AUTH_USER']));
            $smarty->assign('states', Forms::statesArray());
            $smarty->assign('countries', Forms::countriesArray());
            $smarty->assign('action', 'update');
            $smarty->assign('period1_active', PERIOD1_ACTIVE);
            $smarty->assign('period1_value', PERIOD1_VALUE);
            $smarty->assign('period1_interval', Forms::interval2String(PERIOD1_INTERVAL));
            $smarty->assign('amount1', AMOUNT1);
            $smarty->assign('period2_active', PERIOD2_ACTIVE);
            $smarty->assign('period2_value', PERIOD2_VALUE);
            $smarty->assign('period2_interval', Forms::interval2String(PERIOD2_INTERVAL));
            $smarty->assign('amount2', AMOUNT2);
            $smarty->assign('period3_value', PERIOD3_VALUE);
            $smarty->assign('period3_interval', Forms::interval2String(PERIOD3_INTERVAL));
            $smarty->assign('amount3', AMOUNT3);
            $smarty->display(SITE_DOC_ROOT . '/templates/head.tpl');
            $smarty->display(SITE_DOC_ROOT . '/templates/user_edit.tpl');
            $smarty->display(SITE_DOC_ROOT . '/templates/foot.tpl');
        break;
 
 
        case 'insert':
            $err = 0;
 
            // Clean up the passwords
            $_POST['user_password']              = trim($_POST['user_password']);
            $_POST['user_password_confirmation'] = trim($_POST['user_password_confirmation']);
 
            $user = new User();
            $user->user_firstname        = $_POST['user_firstname'];
            $user->user_lastname         = $_POST['user_lastname'];
            $user->user_email            = $_POST['user_email'];
            $user->user_password         = $_POST['user_password'];
            $user->user_telephone        = $_POST['user_telephone'];
            $user->user_fax              = $_POST['user_fax'];
            $user->user_address          = $_POST['user_address'];
            $user->user_address2         = $_POST['user_address2'];
            $user->user_city             = $_POST['user_city'];
            $user->user_state            = $_POST['user_state'];
            $user->user_country          = $_POST['user_country'];
            $user->user_postcode         = $_POST['user_postcode'];
 
            $msg = '';
 
            // Validate data
            $err = $user->validateRegForm();
            if($err > 0){
                $msg .= $err>1?"Some required fields need correction":"A required field needs correction";
            }
 
            if($_POST['user_password'] != $_POST['user_password_confirmation']){
                $err++;
                $msg .= '<br />Passwords do not match';
            } elseif(strlen(trim($_POST['user_password'])) < 5){
                $err++;
                $msg .= '<br />Password is too short';
            }
 
            $smarty = new Smarty();
            $smarty->compile_dir = SITE_DOC_ROOT . '/templates_c';
            if($err > 0){
                $smarty->assign('msg', $err>1?"Some required fields need correction":"A required field needs correction");
                $smarty->assign('user', $user);
                $smarty->assign('states', Forms::statesArray());
                $smarty->assign('countries', Forms::countriesArray());
                $smarty->assign('action', 'insert');
                $smarty->assign('period1_active', PERIOD1_ACTIVE);
                $smarty->assign('period1_value', PERIOD1_VALUE);
                $smarty->assign('period1_interval', Forms::interval2String(PERIOD1_INTERVAL));
                $smarty->assign('amount1', AMOUNT1);
                $smarty->assign('period2_active', PERIOD2_ACTIVE);
                $smarty->assign('period2_value', PERIOD2_VALUE);
                $smarty->assign('period2_interval', Forms::interval2String(PERIOD2_INTERVAL));
                $smarty->assign('amount2', AMOUNT2);
                $smarty->assign('period3_value', PERIOD3_VALUE);
                $smarty->assign('period3_interval', Forms::interval2String(PERIOD3_INTERVAL));
                $smarty->assign('amount3', AMOUNT3);
                $smarty->display(SITE_DOC_ROOT . '/templates/head.tpl');
                $smarty->display(SITE_DOC_ROOT . '/templates/user_edit.tpl');
                $smarty->display(SITE_DOC_ROOT . '/templates/foot.tpl');
                exit();
            }
 
 
            //  Everything is good. Insert the user.
            $user->insertUser();
            if($user->err_no != 0){
                if($user->err_no == 1062){
                    $smarty->assign('msg', 'E-mail adress already registered. <a href="index.php?action=sendpw">Click here if you would like to us to email a password reminder</a>.');
                    $smarty->assign('user', $user);
                    $smarty->assign('states', Forms::statesArray());
                    $smarty->assign('countries', Forms::countriesArray());
                    $smarty->assign('action', 'insert');
                    $smarty->assign('period1_active', PERIOD1_ACTIVE);
                    $smarty->assign('period1_value', PERIOD1_VALUE);
                    $smarty->assign('period1_interval', Forms::interval2String(PERIOD1_INTERVAL));
                    $smarty->assign('amount1', AMOUNT1);
                    $smarty->assign('period2_active', PERIOD2_ACTIVE);
                    $smarty->assign('period2_value', PERIOD2_VALUE);
                    $smarty->assign('period2_interval', Forms::interval2String(PERIOD2_INTERVAL));
                    $smarty->assign('amount2', AMOUNT2);
                    $smarty->assign('period3_value', PERIOD3_VALUE);
                    $smarty->assign('period3_interval', Forms::interval2String(PERIOD3_INTERVAL));
                    $smarty->assign('amount3', AMOUNT3);
                    $smarty->display(SITE_DOC_ROOT . '/templates/head.tpl');
                    $smarty->display(SITE_DOC_ROOT . '/templates/user_edit.tpl');
                    $smarty->display(SITE_DOC_ROOT . '/templates/foot.tpl');
                    exit();
                }else{
                    Error::errorMsg($user->err_msg);
                }
                exit();
            }
            // Send mail to autoresponder
            if(AUTORESPOND_ACTIVE != 0){
                $mail = new Mailer();
                $mail->from    = $user->user_firstname . ' ' . $user->user_lastname . ' <' . $user->user_email . '>';
                $mail->to      = AUTORESPOND_TO;
                $mail->subject = AUTORESPOND_SUBJECT;
                $mail->msg     = AUTORESPOND_BODY;
                $mail->send();  
            }
            [color=#BF0000]///////////here is what causes the error////////////[/color]
            header('Location: index.php?action=pay&user_id=' . $user->user_id . '&user_membership=' . $_POST['user_membership']);
        break;
 
 
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: what is this error and what would i do to fix it?

Post by temidayo »

I guess line 51 in the code pasted correspond to line 151 where you are getting the problem.

Remove the spaces at the beginning of the script. Anything sent to the browser means the header has been sent
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: what is this error and what would i do to fix it?

Post by malcolmboston »

a blank line (eg #1 of your quoted code) will also cause this.
Post Reply