Jump to content

cannot modify header information


piano0011

Recommended Posts

Hey guys!I have the following error and I am not sure why because I thought that we could include the header.php and footer.php file at the top?

image.thumb.png.b2f5cb52ad1598d230f63ad7fd208ded.png

 

I will include both my footer.php file and level.php:

This is my footer.php file:

<!DOCTYPE html>
<html>
<head>
    <title>Copyright 2018</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Aldrich" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
</head>
<body>
    <footer>
<div class="copyright clearfix">
    <div class="container clearfix">
    <div class="text float left">
       Copyright PianoCourse101 2018
    </div>
    
    <ul class="links float right">
        <li><a href=""><i class="fab fa-facebook-square"></i></a></li>
        <li><a href=""><i class="fab fa-twitter-square"></i></a></li>
        <li><a href=""><i class="fab fa-instagram"></i></a></li>
        <li><a href=""><i class="fab fa-youtube-square"></i></a></li>
    </ul>
</div>
</div>
</footer>
</body>
</html>

This is my level1.php file

<!DOCTYPE html>
<html>
<head>
   <title></title>
   <meta charset="utf-8">
   <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<?php


include_once 'header.php';
include_once 'footer.php';


$level1promo_expirydate = date('Y-m-d H:i:s', strtotime("+2 day"));
$paidbydate = date('Y-m-d H:i:s', strtotime("+2 day"));
$emailreminder = 1;
$emailreminderreset = null;
$subscriptionplandelete = null;
$paidbydatedelete = null;
$subscriptionplandatedelete = null;
$expirydatedelete = null;
$feemonthlysdelete = null;
$feesyearlydelete = null;
$paidreset = null;
$totalfees = null;
$overdue = 1;
$overduereset = 0;
$activatereset = 0;
$level1promo_activate = 0;

if(!isset($_SESSION['u_uid'])) {
  header("Location: index.php?level1=notlogin");
  exit();
} else {
  include_once 'includes/dbh.php';



                           //Created a template
                            $sql = "SELECT * FROM memberships WHERE user_uid = ?;";
                            //Create a prepared statement

                            $stmt = mysqli_stmt_init($conn);
                            //Prepare the prepared statement
                            if (!mysqli_stmt_prepare($stmt, $sql)) {
                                echo 'SQL statement failed';
                            } else {
                                 //Bind parameters to the placeholder
                                 mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
                                 //Run parameters inside database
                                 mysqli_stmt_execute($stmt);
                                 
                                    $result = mysqli_stmt_get_result($stmt);

                                 while ($row = mysqli_fetch_assoc($result))  {


                                 
                                
                                     
                                   if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 0 && $row['level1promo_activate'] == 0) {
                                      header("Location: update.php?level1=notactivated");
                                      exit();
                                   } else {
                                     if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['emailreminder'] == 0 && $row['overdue'] == 0 && $row['paid'] == 0 && $row['feesmonthly'] != 0 && date("Y-m-d H:i:s") > $row['paidbydate']) {

                                        

                                        $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 monthly subscriptionplan payment is overdue: Please pay by the ".$paidbydate;
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". It has now been extended to the following due date ".$paidbydate."\n\nPlease make sure that you have made your payment ASAP in order to access your Level 1 videos by the current due date. \n\nFailure to make payment will result in the cancellation of your Level 1 monthly subscriptionplan";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET paidbydate = ?, emailreminder = ?, overdue = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "siis", $paidbydate, $emailreminder, $overdue, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 
                                            

                                        
                                     } 

                                             header("Location: update.php?level1=overdue");
                                             exit();

                                     }  else {
                                          if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['emailreminder'] == 1 && $row['overdue'] == 1 && $row['paid'] == 0 && $row['feesmonthly'] != 0 && date("Y-m-d H:i:s") > $row['paidbydate']) {
                                          
                                        $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 monthly subscriptionplan payment has been cancelled!";
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". Your Level 1 monthly subscriptionplan has been cancelled because you have failed to make payment and already have received an email reminder! \n\nPlease subscribe again if you wish to access your Level 1 videos!";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET subscriptionplan = ?, subscriptionplandate = ?, feesmonthly = ?, expirydate = ?, paidbydate = ?, emailreminder = ?, overdue = ?, activate = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "ssissiiis", $subscriptionplandelete, $subscriptionplandatedelete, $feemonthlysdelete, $expirydatedelete, $paidbydatedelete, $emailreminderreset, $overduereset, $activatereset, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 

                                        

                                          }

                                          header("Location: update.php?level1=cancelled");
                                          exit();

                            } else {
                                        if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['emailreminder'] == 0 && $row['overdue'] == 0 && $row['paid'] == 0 && $row['feesyearly'] != 0 && date("Y-m-d H:i:s") > $row['paidbydate']) {

                                        $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 yearly subscriptionplan payment is overdue: Please pay by the ".$paidbydate;
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". It has now been extended to the following due date ".$paidbydate."\n\nPlease make sure that you have made your payment ASAP in order to access your Level 1 videos by the current due date. \n\nFailure to make payment will result in the cancellation of your Level 1 yearly subscriptionplan";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET paidbydate = ?, emailreminder = ?, overdue = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "siis", $paidbydate, $emailreminder, $overdue, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 

                                        
                                     } 

                                             header("Location: update.php?level1=overdue");
                                             exit();

                                        } else {
                                             if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['emailreminder'] == 1 && $row['overdue'] == 1 && $row['paid'] == 0 && $row['feesyearly'] != 0 && date("Y-m-d H:i:s") > $row['paidbydate']) {
                                          
                                        $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 yearly subscriptionplan payment has been cancelled!";
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". Your Level 1 yearly subscriptionplan has been cancelled because you have failed to make payment and already have received an email reminder! \n\nPlease subscribe again if you wish to access your Level 1 videos!";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET subscriptionplan = ?, subscriptionplandate = ?, feesmonthly = ?, expirydate = ?, paidbydate = ?, emailreminder = ?, overdue = ?, activate = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "ssissiiis", $subscriptionplandelete, $subscriptionplandatedelete, $feemonthlysdelete, $expirydatedelete, $paidbydatedelete, $emailreminderreset, $overduereset, $activatereset, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 

                                        

                                          }

                                          header("Location: update.php?level1=cancelled");
                                          exit();
                                          
                                          // Up to this point, the code is working

                                        } else {
                                            if ($row['subscriptionplan'] === 'Level 1' && $row['feesmonthly'] != 0 && $row['activate'] == 1 && $row['paid'] == 1 && date("Y-m-d H:i:s") > $row['expirydate']) {
                                            
                                             $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 monthly subscriptionplan payment has been cancelled!";
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". Your Level 1 monthly subscriptionplan has been cancelled because you have failed to make payment and already have received an email reminder! \n\nPlease subscribe again if you wish to access your Level 1 videos!";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET subscriptionplan = ?, subscriptionplandate = ?, feesmonthly = ?, paid = ?, expirydate = ?, paidbydate = ?, emailreminder = ?, overdue = ?, activate = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "ssiissiiis", $subscriptionplandelete, $subscriptionplandatedelete, $feemonthlysdelete, $paidreset, $expirydatedelete, $paidbydatedelete, $emailreminderreset, $overduereset, $activatereset, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 

                                        

                                          }

                                          

                                            header("Location: update.php?level1=expired");
                                            exit();
                                            } else {
                                                if ($row['subscriptionplan'] === 'Level 1' && $row['feesyearly'] != 0 && $row['activate'] == 1 && $row['paid'] == 1 && date("Y-m-d H:i:s") > $row['expirydate']) {
                                            
                                             $company = "pianocourse101@hotmail.com";
                                        $subject = "Level 1 yearly subscriptionplan payment has been cancelled!";
                                        $mailTo = $_SESSION['u_email'];
                                        $headers = "From: ".$company;
                                        $txt = "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Your payment was due on the ".$row['paidbydate'].". Your Level 1 yearly subscriptionplan has been cancelled because you have failed to make payment and already have received an email reminder! \n\nPlease subscribe again if you wish to access your Level 1 videos!";

                                        mail($mailTo, $subject, $txt, $headers);

                                        $sql = "UPDATE memberships
                                                SET subscriptionplan = ?, subscriptionplandate = ?, feesyearly = ?, paid = ? expirydate = ?, paidbydate = ?, emailreminder = ?, overdue = ?, activate = ?
                                                WHERE user_uid = ?

                                               ";
                                        
                                        $stmt = mysqli_stmt_init($conn);
                                        //Prepare the prepared statement
                                        if (!mysqli_stmt_prepare($stmt, $sql)) {
                                            echo 'SQL statement failed';
                                        } else {
                                             //Bind parameters to the placeholder
                                             mysqli_stmt_bind_param($stmt, "ssiissiiis", $subscriptionplandelete, $subscriptionplandatedelete, $feeyearlysdelete, $paidreset, $expirydatedelete, $paidbydatedelete, $emailreminderreset, $overduereset, $activatereset, $_SESSION['u_uid']);
                                             //Run parameters inside database
                                             mysqli_stmt_execute($stmt); 

                                        

                                          }

                                          

                                            header("Location: update.php?level1=expired");
                                            exit();

                                            // last working code!

                                            } if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['paid'] == 1 && date("Y-m-d H:i:s") <= $row['expirydate']) {
                                              header("Location: level1videos.php?levelvideos=success");
                                              exit();
                                            } else {
                                                 if ($row['subscriptionplan'] === 'Level 1' && $row['activate'] == 1 && $row['paid'] == 0 && date("Y-m-d H:i:s") <= $row['expirydate']) {
                                              header("Location: update.php?level1=notpaid");
                                              exit();
                                            } else {
                                           if ($row['subscriptionplan2'] === 'Level 2' && $row['level2promo_activate'] == 1 && date("Y-m-d H:i:s") > $row['expirydate2'] && $row['paid2'] == 0 && $row['activate2'] == 0) {
                                         
                                         header("Location: update.php?level1promo=expired");
                                         exit();
                                      }  else {
                                           if ($row['subscriptionplan2'] === 'Level 2' && $row['level2promo_activate'] == 1 && date("Y-m-d H:i:s") <= $row['expirydate2'] && $row['paid2'] == 0 && $row['activate2'] == 0) {
                                         
                                             header("Location: level2videos.php?level1promo=success");
                                             exit();
                                      } else {
                                         header("Location: update.php?level1=notchosen");
                                         exit();
                                      }
                                              
                                    }      
                                    }              


                                      }      
                                              
                                    }      
                                                 
                          }
                        }
                      }
                    }
                  }
                 }
               }
              }

 

Link to comment
Share on other sites

The error message is pretty explicit.  Your script in total has apparently output something prior to the call to the header function.  Look for a blank line outside of your php code block or an echo/print statement.  You cannot output anything to the client before calling header.  As with any php error message, ;ook at the given line number for a clue.

Link to comment
Share on other sites

As ginerjm mentioned, nothing can be outputted to the screen before calling the header() function. Note that your level1.php script has several lines of output at the top. The script will need to be rewritten so that you do all your processing at the top. Then all of the output would be done at the bottom of the script.

Link to comment
Share on other sites

In what tutorial did they tell you to duplicate the opening and closing HTML tags? All these tags and the closing counterparts only go in a document ONE time.

 

<!DOCTYPE html>
<html>
<head>
    <title>Copyright 2018</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Aldrich" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
</head>
<body>
Link to comment
Share on other sites

Hey piano0011!

Browsers tend to do all sorts of things to try and present something, even when the input is mangled or malformed HTML.  

Benanamen pointed out your issue:  You are repeatedly injecting full HTML documents into the same HTML document.  

Candidly, the old header.php, footer.php paradigm is limiting in many ways.  For example, for SEO purposes the single most important thing for your pages is the Title.  The title tag needs to be descriptive, AND your page should also have an h1 that duplicates the title.

If you have a static header.php script that includes the header, you will inevitably need a way to inject the title in some way.  

But lets forget about that for a moment and just get you to a place where you understand the basics of HTML/HTTP and how PHP plays with these.

With PHP, as soon as you start output which in your level1.php file is started immediately due to the fact that you begin with an HTML block! the HTTP headers get sent to the client.  This is rarely what you want in a PHP application.  

There are many things you might want to do first, like setting up a php session, querying your database, or checking for things in $_SERVER or $_COOKIE.  Don't start your scripts with an HTML block as you are doing in level1.php!

I don't know what is in header.php, but as Benanamen explained, your footer.php should not have the same repeated html, header etc. tags.  Typically a footer only has a navigation menu, copyright notices and perhaps some included social media buttons along with possibly some included .js scripts.  

I would highly encourage you to familiarize yourself with the Chrome dev tools and in particular the network tab.  This will help you explore the underlying HTTP protocol and aid your understanding of how your PHP scripts in conjunction with the web server actually respond to browser requests.

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.