Jump to content

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\loginsystem\index.php:57) in C:\xampp\htdocs\loginsystem\index.php on line 87


piano0011

Recommended Posts

This is strange because I have checked line 87 and can't find anything wrong... Maybe, I forgot to closed a tag

 

<?php

include_once 'header.php';
?>





   <section class="main-container">
    
    <img class="pc101" src="includes/pictures/pc101.gif" width="10" height="80" alt="pianocourse101 logo">

 <br></br>

    <div class="main-wrapper">
       <h3>Welcome to PianoCourse101</h3>
       <br></br>
    </div>

    <div class="main-wrapper">
       <h1>At PianoCourse101, your child can now learn how to play Classical music right from the comfort of your own home!<br></br>PianoCourse101 teaching methods are based on the Bastie Piano Basics series and therefore, we highly recommend you to purchase the book prior to your piano lessons!<br></br> At PianoCourse101, you can choose 4 levels beginning with the FREE "Bastien Piano Basics: Primer Level" lessons!<br></br>If you would like a challenge and are ready to progress to the next level, then you can choose to upgrade your free membership to premium membership, where you can access Level 1, Level 2 and Level 3!<br></br>Also, please ensure that you have read the Q/A section of the website and if you have any questions, you can email to our customer support team from the Contact Us section. </h1>
    </div>

    <form class="signup-form" action="newsletters.php" method="POST">
       <label><center>Enter your E-mail Address</center></label>
       <br></br>
       <center><input type="text" name='email' placeholder="Enter E-mail Address"></center>
       <br></br>
       <center><button type="submit" name="submit">Subscribe to PianoCourse101!</button></center>
       <br></br>
    </form>



    <img class="snoopy" src="includes/pictures/snoopy.jpg" width="100" height="80" alt="snoopy playing the piano">

   </section>

   



          

            






  



<?php
   include_once 'footer.php';

?>







      

         

      

       

      
<?php








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

  if(isset($_SESSION['u_uid'])) {
  include_once 'includes/dbh.php';
    // update profile image
 
   
    













    echo '<hr>';
    echo '<center> <h3>Welcome '.$_SESSION['u_first'].'  '.$_SESSION['u_last']. ' </h3></center>';
    echo '<center> <h3>Your last login was at '.$_SESSION['u_session']. '</h3></center>';
    echo '<br></br>';
    echo '<center><h3><a href="practice_diary.php">Click here to access your Practice Diary!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="uploadform.php">Click here to Upload your Profile Image!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="deleteprofile.php">Click here to Delete your Profile Image!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="reward.php">Click here to view your Reward Page!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="referal.php">Click here for Referal Points!</h3></a></center>';

    $sql = "SELECT * FROM review";

    $stmt = mysqli_stmt_init($conn);

    if (!mysqli_stmt_prepare($stmt, $sql)) {
       echo 'SQL error';
    } else {
       mysqli_stmt_execute($stmt);

       $result = mysqli_stmt_get_result($stmt);

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

          echo '<hr>';
          echo '<br></br>';
          echo '<center> '.$row['user_uid']. '</center>';
          echo '<br></br>';
          echo '<center> "'.$row['review']. '"</center>';
          echo '<br></br>';
          echo '<center> '.$row['datesubmitted']. '</center>';             
    }
    

         
  } 
}

}


 $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

         // Primer level error handlers
         
         if (strpos($fullUrl, "primer=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Primer Level Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "primer=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Primer Level Lessons are under maintenance</p>";
               exit();
         }

         if (strpos($fullUrl, "primer=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }



         



         // Level 1 error handlers

         if (strpos($fullUrl, "level1=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 1 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons have been cancelled!</p>";
               exit();
         }


         if (strpos($fullUrl, "level1=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 1 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level1=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 1 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }




       


         

         // Level 2 error handlers

         if (strpos($fullUrl, "level2=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 2 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons have been cancelled!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 2 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level2=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 2 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }





         

         // Level 3 error handlers

         if (strpos($fullUrl, "level3=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 3 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons have been cancelled!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 3 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level3=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 3 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }

         // Contact form error handlers


         if (strpos($fullUrl, "contact=mustbeloginfirst") == true) {
               echo "<br>";
               echo "<p class='error'>You must login first before using the contact form!</p>";
               exit();
         }




          









 

Link to comment
Share on other sites

I feel so stupid that I can't see where is the problem here... I have open a new php tag for each php that I have...maybe I didn't close my html tags? I get it... I can't redirect to the same page....So, I guess that I can't use header after an html output? I must use it before the html? It still doesn't work.....

..

Link to comment
Share on other sites

You cannot send headers once any output as already been sent to the browser. All the html code and blank lines (except the few inside <?php...?> tags) prior to line 87 have already been sent.

Do your php processing before you start outputting html.

Link to comment
Share on other sites

1 minute ago, piano0011 said:

Thanks guys! I have heard somewhere that you can use ob_start()? I will try to do the php first before any html in the future...

You don't need ob_start(). You should be able to modify the code so that header() is called, if needed, before any HTML is outputted to the screen.

Link to comment
Share on other sites

I tried putting my html code at the bottom of the page like this:

 

<?php








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

  if(isset($_SESSION['u_uid'])) {
    include_once 'header.php';
  include_once 'includes/dbh.php';
    // update profile image
 
   
    













    echo '<hr>';
    echo '<center> <h3>Welcome '.$_SESSION['u_first'].'  '.$_SESSION['u_last']. ' </h3></center>';
    echo '<center> <h3>Your last login was at '.$_SESSION['u_session']. '</h3></center>';
    echo '<br></br>';
    echo '<center><h3><a href="practice_diary.php">Click here to access your Practice Diary!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="uploadform.php">Click here to Upload your Profile Image!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="deleteprofile.php">Click here to Delete your Profile Image!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="reward.php">Click here to view your Reward Page!</h3></a></center>';
    echo '<br></br>';
    echo '<center><h3><a href="referal.php">Click here for Referal Points!</h3></a></center>';

    $sql = "SELECT * FROM review";

    $stmt = mysqli_stmt_init($conn);

    if (!mysqli_stmt_prepare($stmt, $sql)) {
       echo 'SQL error';
    } else {
       mysqli_stmt_execute($stmt);

       $result = mysqli_stmt_get_result($stmt);

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

          echo '<hr>';
          echo '<br></br>';
          echo '<center> '.$row['user_uid']. '</center>';
          echo '<br></br>';
          echo '<center> "'.$row['review']. '"</center>';
          echo '<br></br>';
          echo '<center> '.$row['datesubmitted']. '</center>';             
    }
    

         
  } 
}

}

include_once 'footer.php';

?>


<?php




 $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

         // Primer level error handlers
         
         if (strpos($fullUrl, "primer=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Primer Level Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "primer=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Primer Level Lessons are under maintenance</p>";
               exit();
         }

         if (strpos($fullUrl, "primer=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }



         



         // Level 1 error handlers

         if (strpos($fullUrl, "level1=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 1 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons have been cancelled!</p>";
               exit();
         }


         if (strpos($fullUrl, "level1=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 1 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level1=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 1 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 1 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level1=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }




       


         

         // Level 2 error handlers

         if (strpos($fullUrl, "level2=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 2 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons have been cancelled!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 2 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level2=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 2 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 2 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level2=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }





         

         // Level 3 error handlers

         if (strpos($fullUrl, "level3=notactivated") == true) {
               echo "<br>";
               echo "<p class='error'>You have not activated your Level 3 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=overdue") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons fee is overdue!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=cancelled") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons have been cancelled!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=expired") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons have expired!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notpaid") == true) {
               echo "<br>";
               echo "<p class='error'>You have not paid for your Level 3 Lessons!</p>";
               exit();
         }
         
          if (strpos($fullUrl, "level3=maintenance") == true) {
               echo "<br>";
               echo "<p class='error'>Your Level 3 Lessons are under maintenance!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notchosen") == true) {
               echo "<br>";
               echo "<p class='error'>You have not subscribed for Level 3 Lessons!</p>";
               exit();
         }

         if (strpos($fullUrl, "level3=notlogin") == true) {
               echo "<br>";
               echo "<p class='error'>You have not login!</p>";
               exit();
         }

         // Contact form error handlers


         if (strpos($fullUrl, "contact=mustbeloginfirst") == true) {
               echo "<br>";
               echo "<p class='error'>You must login first before using the contact form!</p>";
               exit();
         }

?>


          

<section class="main-container">
    
    <img class="pc101" src="includes/pictures/pc101.gif" width="10" height="80" alt="pianocourse101 logo"/>

 <br></br>

    <div class="main-wrapper">
       <h3>Welcome to PianoCourse101</h3>
       <br></br>
    </div>

    <div class="main-wrapper">
       <h1>At PianoCourse101, your child can now learn how to play Classical music right from the comfort of your own home!<br></br>PianoCourse101 teaching methods are based on the Bastie Piano Basics series and therefore, we highly recommend you to purchase the book prior to your piano lessons!<br></br> At PianoCourse101, you can choose 4 levels beginning with the FREE "Bastien Piano Basics: Primer Level" lessons!<br></br>If you would like a challenge and are ready to progress to the next level, then you can choose to upgrade your free membership to premium membership, where you can access Level 1, Level 2 and Level 3!<br></br>Also, please ensure that you have read the Q/A section of the website and if you have any questions, you can email to our customer support team from the Contact Us section. </h1>
    </div>

    <form class="signup-form" action="newsletters.php" method="POST">
       <label><center>Enter your E-mail Address</center></label>
       <br></br>
       <center><input type="text" name='email' placeholder="Enter E-mail Address"></center>
       <br></br>
       <center><button type="submit" name="submit">Subscribe to PianoCourse101!</button></center>
       <br></br>
    </form>



    <img class="snoopy" src="includes/pictures/snoopy.jpg" width="100" height="80" alt="snoopy playing the piano" />

   </section>

   



          
</body>
</html>

      

Now the screen is showing this:

 

image.thumb.png.acccead94282f57c3ef62aa106425dfc.png

Link to comment
Share on other sites

your page is redirecting to itself, over and over, until the browser has had enough. your program logic is not correct.

you need to decide what the code on your page is going to do if the user is logged in and if the user isn't logged in, starting with what is the purpose of this page? is it the login form processing and login form (based on the loginsystem in the path), or is it the site's main index.php page?

if you are trying to make a single page that has form processing code and the form on it, the only redirect you should have is at the end of successfully completing the post method form processing code, in which case you should redirect to the exact same URL of the page to cause a get request for the page so that the browser won't try to re-submit the post data if you refresh the page or navigate away from and back to it.

Link to comment
Share on other sites

Thanks for the feedback.. i am new to php so have been following mmtuts and he does a fair bit of cutting and pasting and i must have added more codes to this page such as displaying error handlers... it should be the main page that the user can see if log in..

 

I also think that i forgot to open my html tag....

Link to comment
Share on other sites

Hey Mac_gyver.... love the show by the way.... As you mentioned, I changed the redirect page url and it is working... and after checking all of my other Location, I did redirect to a different page. Is this the main problem that I can't redirect to the same page? It could just be my logic that if the user is not logged in, they should be redirect to the login page and not to the main index php... my bad logic... but as someone did mention, must I always need to have the php code before any html output or can you have html output first? I guess it can be confusing to include both html and php codes, I should stick with using one of the other...

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.