1

Just to give you a short background, I am working with a referral program and the main feature of it is referring someone.

In my website. I have registration page, login page, successful registration page, referral page and referral list.

For example, if you are a user, you have to register through registration page. If you successfully register on my page, the next page will be the successful registration page. There is a button there to go to the referral page to refer someone.

The problem I encounter is, I register as a new user. So definitely, I filled up all necessary information to registration page, after I successfully register, the next page after that is showing the successful registration page and in that page there is a button that once you click it, it will go to referral form page.

For example, I will now refer someone, so I filled up all information, so when I tried to submit my referral there is an error that prompt at my page

Can anyone tell me which line of my code is triggering this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/thecommissioner/public_html/crm/include/Webservices/Utils.php:880) in /home/thecommissioner/public_html/crm/modules/Webforms/capture_old.php on line 97

but the referral added on my referral list, so when I tried to refer again, this error won't show anymore... even if I refer several times, this error didn't show anymore. It just shows on the first referral try of a new created account. I don't know what the problem is.

This just shows on my first try to referring somebody, but after that, when I tried to refer more, this wont show anymore and I already added my referral. Can someone help me to figure this out?

I know there are several lessons there and I've already read different posts in stackoverflow about this and I'm still vague about it. And would you mind telling me what new code I can use instead of my current code? I cannot test if my page is working because of this.

Here's my code:

<!DOCTYPE html>
<?php
include('../include/dbconnection.php');
include('../include/functions.php');

if(!isset($_SESSION))
{
session_start();
}
$empid = $_SESSION['SESS_EMP_ID'];
$conid = $_SESSION['SESS_CONID'];
$fName = $_SESSION['SESS_FIRSTNAME'];
$lName = $_SESSION['SESS_LASTNAME'];
$contactNo = $_SESSION['SESS_CONTACT_NO'];
$mobile = $_SESSION['SESS_MOBILE'];
$email = $_SESSION['SESS_EMAIL'];
$bday = $_SESSION['SESS_BDAY'];

if($conid == '')
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
    window.location.href='index.php';
    </SCRIPT>");
}

else
{
//Nothing
}
?>
<html lang="en">

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/skeleton.css">
<link rel="stylesheet" href="../css/successReg_style.css">
<link rel="icon" type="image/png" href="../images/cvglogo.png">
<link rel="short icon" href="../images/favicon.ico">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<link rel="stylesheet" href="../css/animate.css">
</head>

<body>

 <!--Here the Header goes-->
 <?php include('include/logoheader.php'); ?>


    <!-- Overall Contect for Responsive Purposes-->
    <div class="allcontent">
        <div class="row">
                <div class="twelve columns" style="margin-top:0%;">

                    <!-- Here the Main Content goes-->
                    <div="maincontent">
                        <center>
                            <h3>Congratulations and Welcome to the Circle!</h3>
                            <br>

                            <div class=" animated zoomIn socialmedia">
                                <ul>
                                    <li>
                                    <img class="logos" src="../images/tick.png">
                                    </li>  
                                </ul>
                            </div>

                            <!-- This is the welcome Introduction -->
                            <div class="welcome">
                                <p>Now that you’re part of the most awesome group on the planet, why not share the glory with your friends. There’s no happier  
                                team 
                                player than a team player with his friends.</p>
                                <span class="hit">Don’t be shy. Hit the button. Refer your friend!</span><br>


                <!-- This is Just a GIF arrow down -->
                            <div class="demo-wrapper">
                                <div class="html5-dialog">
                                        <div class="gif">
                                            <img src="../images/scroll-down.gif">
                                        </div>
                                        <?php include('GlobalConstant.php'); ?>
                                        <!-- But here goes the button for "I have someone in mind" -->
                                        <a href="<?php echo employee_refer; ?>"><button class="navbutton">I have someone in mind</button>   
                                        </a>
                                </div>
                         </div>
                </div>
        </div>
 </div>

             <!-- Here the footer goes-->
         <center><?php include("include/footer.php"); ?></center>

 </body>
 </html>

The error:

Warning: Cannot modify header information - headers already sent by (output started at /home/thecommissioner/public_html/crm/include/Webservices/Utils.php:880) in /home/thecommissioner/public_html/crm/modules/Webforms/capture_old.php on line 97

just shows on my first attempt of referring then after that, when I referred more, the above warning/error didn't show again.

If those warning just shows on my first attempt of referring, why it doesn't show the next time I referring again? It just shows on my first try.

arci
  • 31
  • 6

2 Answers2

0

You need to send header before ANY output is sent. That means before that HTML, on top of page.

OR, as RamRider suggested, use output buffering.

Put

ob_start() 

On very top of page and

ob_end_clean() 

On very bottom

david8
  • 444
  • 9
  • 23
0

You need to put the session_start() function on top your code. Otherwise sometimes php will throw the exception headers already sent.

    <?php
    session_start();

    include('../include/dbconnection.php');
    include('../include/functions.php');


    $empid = $_SESSION['SESS_EMP_ID'];
    $conid = $_SESSION['SESS_CONID'];
    $fName = $_SESSION['SESS_FIRSTNAME'];
    $lName = $_SESSION['SESS_LASTNAME'];
    $contactNo = $_SESSION['SESS_CONTACT_NO'];
    $mobile = $_SESSION['SESS_MOBILE'];
    $email = $_SESSION['SESS_EMAIL'];
    $bday = $_SESSION['SESS_BDAY'];

    if($conid == '')
    {
    echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.location.href='index.php';
        </SCRIPT>");
    }

    else
    {
    //Nothing
    }
    ?>
   <!DOCTYPE html>
    <html lang="en">

    <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="../css/normalize.css">
    <link rel="stylesheet" href="../css/skeleton.css">
    <link rel="stylesheet" href="../css/successReg_style.css">
    <link rel="icon" type="image/png" href="../images/cvglogo.png">
    <link rel="short icon" href="../images/favicon.ico">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript"></script>
    <link rel="stylesheet" href="../css/animate.css">
    </head>

    <body>

     <!--Here the Header goes-->
     <?php include('include/logoheader.php'); ?>


        <!-- Overall Contect for Responsive Purposes-->
        <div class="allcontent">
            <div class="row">
                    <div class="twelve columns" style="margin-top:0%;">

                        <!-- Here the Main Content goes-->
                        <div="maincontent">
                            <center>
                                <h3>Congratulations and Welcome to the Circle!</h3>
                                <br>

                                <div class=" animated zoomIn socialmedia">
                                    <ul>
                                        <li>
                                        <img class="logos" src="../images/tick.png">
                                        </li>  
                                    </ul>
                                </div>

                                <!-- This is the welcome Introduction -->
                                <div class="welcome">
                                    <p>Now that you’re part of the most awesome group on the planet, why not share the glory with your friends. There’s no happier  
                                    team 
                                    player than a team player with his friends.</p>
                                    <span class="hit">Don’t be shy. Hit the button. Refer your friend!</span><br>


                    <!-- This is Just a GIF arrow down -->
                                <div class="demo-wrapper">
                                    <div class="html5-dialog">
                                            <div class="gif">
                                                <img src="../images/scroll-down.gif">
                                            </div>
                                            <?php include('GlobalConstant.php'); ?>
                                            <!-- But here goes the button for "I have someone in mind" -->
                                            <a href="<?php echo employee_refer; ?>"><button class="navbutton">I have someone in mind</button>   
                                            </a>
                                    </div>
                             </div>
                    </div>
            </div>
     </div>

                 <!-- Here the footer goes-->
             <center><?php include("include/footer.php"); ?></center>

     </body>
     </html>

If you are still experiencing the issue try ob_start() and ob_flush() .. Anyways this stackoverflow article about headers already sent is worth reading though Stackoverflow link

Community
  • 1
  • 1
Jijo John
  • 1,375
  • 9
  • 21