首页 > 解决方案 > 如何让下面的代码先用php开始,再用html

问题描述

我试图让以下主页正常工作,同时保持必须先放置 php 然后再放置 html 的规则。我试图把整个 html 代码放在最后,但是我的登录功能看起来不同并且没有样式。我正在尝试这样做以避免标头已发送问题,这可能很烦人。即使使用 ob_start() 也不是一直都有帮助......

<?php
   ob_start();
session_start();
 ?>

 <!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>PianoCourse101</title>
  <link rel="stylesheet" type="text/css" href="style4.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous">
</head>
<body>


  <div class="nav">
       <input type="checkbox" id="menu" />
       <label for="menu" id="nav-icon">&#9776;</label>

       <div class="multi-level">
          <div class="item">
             <input type="checkbox" id="A" />
             <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="A">Home</label>
             <ul>
                <li><a href="index.php">Home Page</a></li>

             </ul>
          </div>
          <div class="item">
                       <input type="checkbox" id="B" />
                       <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="B">Administrator's Section</label>

                       <ul>
                           <li><a href="update_database_maintenance.php">Insert Database Maintenance</a></li>
                           <li><a href="updateexisting_database_maintenance_primer.php">Update Database Maintenance for Primer Level</a></li>
                           <li><a href="updateexisting_database_maintenance_level1.php">Update Database Maintenance for Level 1</a></li>
                           <li><a href="updateexisting_database_maintenance_level2.php">Update Database Maintenance for Level2</a></li>
                           <li><a href="updateexisting_database_maintenance_level3.php">Update Database Maintenance for Level 3</a></li>
                         <li><a href="create_music_cat.php">Create Music Category</a></li>
                           <li><a href="create_music_sub.php">Create Music Sub Category</a></li>
                           <li><a href="admin_create_music_topic.php">Create Music Topic</a></li>
                           <li><a href="admin_create_level1promo.php">Create Level 1 Promotion Competition</a></li>
                           <li><a href="admin_create_level2promo.php">Create Level 2 Promotion Competition</a></li>
                           <li><a href="admin_create_level3promo.php">Create Level 3 Promotion Competition</a></li>
                           <li><a href="level1promo_competitions_participants.php">Display Level 1 Promo Competitions' Participants</a></li>
                           <li><a href="level2promo_competitions_participants.php">Display Level 2 Promo Competitions' Participants</a></li>
                           <li><a href="level3promo_competitions_participants.php">Display Level 3 Promo Competitions' Participants</a></li>
                           <li><a href="level1promo_competitions_winner_form.php">Generate Level 1 Promo Competitions' Winner</a></li>
                           <li><a href="level2promo_competitions_winner_form.php">Generate Level 2 Promo Competitions' Winner</a></li>
                           <li><a href="level3promo_competitions_winner_form.php">Generate Level 3 Promo Competitions' Winner</a></li>
                           <li><a href="admin_students_rewardpoints.php">Display Students' Reward points</a></li>
                           <li><a href="admin_nonpremium_users.php">Display Non Premium Users</a></li>
                           <li><a href="admin_level1_users.php">Display Level 1 Premium Users</a></li>
                            <li><a href="admin_level2_users.php">Display Level 2 Premium Users</a></li>
                             <li><a href="admin_level3_users.php">Display Level 3 Premium Users</a></li>
                             <li><a href="admin_students.php">Display Students' Details</a></li>
                             <li><a href="level1promo.php">Display Level 1 Promo Qualified Users</a></li>
                             <li><a href="level2promo.php">Display Level 2 Promo Qualified Users</a></li>
                             <li><a href="level3promo.php">Display Level 3 Promo Qualified Users</a></li>
                             <li><a href="level1promo_manually_activate.php">Activate Level 1 Promo Competitions Manually</a></li>
                             <li><a href="level2promo_manually_activate.php">Activate Level 2 Promo Competitions Manually</a></li>
                             <li><a href="level3promo_manually_activate.php">Activate Level 3 Promo Competitions Manually</a></li>
                             <li><a href="ticket.php">Ticket Reply</a></li>
                            <li><a href="contact_moderators.php">Contact Moderators</a></li>
                       </ul>
                    </div>

                   <div class="item">
                       <input type="checkbox" id="C" />
                       <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="C">Moderator's Section</label>

                       <ul>
                          <li><a href="ticket_moderator.php">Ticket Reply</a></li>


                       </ul>
                    </div></li>


               <div class="item">
             <input type="checkbox" id="D" />
            <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="D">Member's Section</label>
             <ul>


                        <li><div class="sub-item">
                       <input type="checkbox" id="D-A" />
                       <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="D-A">Watch Videos</label>
                       <ul>
                          <li><a href="primer.php">Primer Videos</a></li>
                          <li><a href="level1.php">Level 1 Videos</a></li>
                          <li><a href="level2.php">Level 2 Videos</a></li>
                          <li><a href="level3.php">Level 3 Videos</a></li>
                       </ul>
                    </div></li>

                    <li><a href="practice_diary.php">Practice Diary</a></li>
                    <li><a href="download.php">Download Section</a></li>
                    <li><a href="upload.php">Upload Homework</a></li>
                    <li><a href="practice_diary_view.php">Practice Diary View</a></li>
                    <li><a href="display_music_forum.php">Music Forum</a></li>
                    <li><a href="update.php">Student's General Information</a></li>
                    <li><a href="update_profile.php">Update Student's Information</a></li>
                    <li><a href="reward_points.php">Student's Reward Points</a></li>
                    <li><a href="donation_button.php">Donation</a></li>
                    <li><a href="review.php">Write a Review</a></li>
                    <li><a href="ticket_view.php">View Ticket</a></li>
                    <li><a href="level1promoform.php">Level 1 Promo Form</a></li>
                    <li><a href="level2promoform.php">Level 2 Promo Form</a></li>
                    <li><a href="level3promoform.php">Level 3 Promo Form</a></li>
                    <li><a href="level1promo_competitions.php">Display Level 1 Promo Competitions</a></li>
                    <li><a href="level2promo_competitions.php">Display Level 2 Promo Competitions</a></li>
                    <li><a href="level3promo_competitions.php">Display Level 3 Promo Competitions</a></li>
                    <li><a href="level1promo_competitions_winner_announcement.php">Level 1 Promo Competition Winner</a></li>
                    <li><a href="level2promo_competitions_winner_announcement.php">Level 2 Promo Competition Winner</a></li>
                    <li><a href="level3promo_competitions_winner_announcement.php">Level 3 Promo Competition Winner</a></li>
             </ul>
          </div> 
          <div class="item">
             <input type="checkbox" id="E" />
             <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="E">About PianoCourse101</label>

             <ul>
                <li><a href="contact.php">Contact Us</a></li>
                <li><a href="email_retrieval.php">Retrieve E-mail</a></li>
                <li><a href="deleteaccount.php">Delete Account</a></li>
                <li><a href="qa.php">Questions and Answers</a></li>
                <li><a href="activate.php">Activate Membership</a></li>
                <li><a href="databaseprimer.php">Check Database Maintenance for Primer Level</a></li>
                <li><a href="databaselevel1.php">Check Database Maintenance for Level 1</a></li>
                <li><a href="databaselevel2.php">Check Database Maintenance for Level 2</a></li>
                <li><a href="databaselevel3.php">Check Database Maintenance for Level 3</a></li>
                <li><a href="reset.php">Change Password</a></li>
                <li><a href="token_request_primer.php">Token Request: Primer Level</a></li>
                <li><a href="token_request_level1.php">Token Request: Level 1</a></li>
                <li><a href="token_request_level2.php">Token Request: Level 2</a></li>
                <li><a href="token_request_level3.php">Token Request: Level 3</a></li>

             </ul>
          </div>
          <div class="item">
            <input type="checkbox" id="F" />
            <div class="arrow"><i class="fas fa-chevron-circle-down"></i></div><label for="F">Signup</label>

            <ul>
               <li><a href="signup.php">Signup Premium Membership</a></li>
            </ul>
       </div>
   </div>





























</head><body>

  <header>























<div class="nav-login">





















<?php

                  include_once __DIR__.'/user_information.php';

               include_once __DIR__.'/includes/dbh.php';

                if ($_SESSION['u_banned'] == 1) {
        session_unset();
       session_destroy();
        header("Location: index.php?signup2=banned");
                          exit();
    } else { 



                if (isset($_SESSION['u_uid']) && $_SESSION['u_banned'] == 0) {




                   echo '<form action="includes/logout.php" method="POST" class="logout">  
                   <button type="submit" name="submit">Logout</button>
                </form><div class="trophy"><a href="reward_points.php"><i class=" fas fa-trophy fa-4x" title="Click here to view your rewards!"></i></a></div>';



                $sql = "SELECT * FROM users WHERE user_uid = ?;";

$stmt = mysqli_stmt_init($conn);

if (!mysqli_stmt_prepare($stmt, $sql)) {
   echo 'SQL error';
   exit();
} else {
    mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $resultCheck = mysqli_num_rows($result);

    if($resultCheck > 0) {
      while ($row = mysqli_fetch_assoc($result)) {
        $id = $row['user_id'];
        $one = 1;
        $sqlImg = "SELECT * FROM profileimg WHERE userid = ? limit 1;";

        $stmt = mysqli_stmt_init($conn);

        if (!mysqli_stmt_prepare($stmt, $sqlImg)) {
           echo 'SQL error';
           exit();
        } else {
            mysqli_stmt_bind_param($stmt, "i", $id);
            mysqli_stmt_execute($stmt);
            $resultImg = mysqli_stmt_get_result($stmt);

            while ($rowImg = mysqli_fetch_assoc($resultImg)) {
           // echo "<div class ='user-container'>";
                  if ($rowImg['status'] == 0) {
                    $filename = "includes/uploads/profile".$id."*";
                    $fileinfo = glob($filename);
                    $fileext = explode(".", $fileinfo[0]);
                    $fileactualext = $fileext[1];
                    echo "<img class='profile_picture' src='includes/uploads/profile".$id.".".$fileactualext."?".mt_rand()."'>";
                  } else {
                    echo "<img class='default_picture' src='includes/uploads/profiledefault.jpg'>";
                  }



              }
            }
            }


}

   }  



  $date = strip_tags(date('Y-m-d H:i:s', strtotime("+2 day")));   


  if ($_SESSION['u_session'] > $date) {
      echo 'You have not login for 2 days!';
  }



























}else {

                   echo '<form action="includes/login.php" method="POST">
                      <input  type="text" name="uid" placeholder="Username/e-mail">
                       <input  type="password" name="password" placeholder="password">
                        <button type="submit" name="submit" value="submit">Login</button></form>';




              } 


}




echo '</div>';

include_once __DIR__.'/footer.php';

标签: php

解决方案


推荐阅读