PHP评论出现在网页上

时间:2016-03-12 06:44:36

标签: php html

我在我的脚本上注释了PHP评论。但它们仍以HTML格式显示在我的网页上。你知道我该如何解决这个问题吗?

亲切的问候,

/*if (isset($_POST['submitted'])) {
//require_once is similar to 'include' but ensures the code is not copied multiple times
require_once('LoginFunctions.php');*/

此文字显示在我的网页上: the output

我的整个剧本: 这是我的整个脚本,因此您可以确定错误的位置。

<link rel="stylesheet" href="style.css">
<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include 'Header.php';
?>

<style>
    body
    {
        background-color:#FFFFC2;
        alignment-adjust: central; 
        float: none;
        background-image: url("images_1/sea-sanctuaries-siteimage01.jpg");
        alignment-baseline: central;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        height:100%;
    }
    #div_1 {
        width: 40%;
        hight: 80%;
        background-color: bisque;
        border: 5px;
        border-radius: 25px;
    }

    #div_2 {
        font-family: sans-serif;
        padding-bottom: 10px;
        padding-right: 50px;
        margin-top: 5px;
        margin-right: 50px;
    }
</style>
<body>
    <div id="container">
        <br>


        <?php
        /*
          if($_DEBUG)
          {
          ini_set('display_errors', 1);
          ini_set('log_errors', 1);
          ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
          error_reporting(E_ALL);
          }


          $page_title = 'Login';/* */

//in this page we do things slightly differently - the code for validation and displaying messages is done
//before we display the form 
        echo '<div id = "div_1><h1>Login</h1>';

//display the form
        echo '<div id="div_2"><div id="div_2">
   <form action="index.php" method="post">
       <label>UserName<br>
       <span class="small">enter your username</span>
       </label>
       <input type="text" name="UserName" value=""/>

       <label><br>Password<br>
       <span class="small">enter your password</span>
       </label>
       <input type="password" name="Password" />

       <button type="submit" name="submit" value="Login" />Log in</button>
       <input type ="hidden" name="submitted" value="TRUE">
     </form>
     </div>
</div>';

        /* if (isset($_POST['submitted'])) {
          //require_once is similar to 'include' but ensures the code is not copied multiple times
          require_once('LoginFunctions.php');

          //list() is a way of assigning multiple values at the same time
          //checkLogin() function returns an array so list here assigns the values in the array to $check and $data
          list($check, $data) = checkLogin($_POST['UserName'], $_POST['Password']);


          if ($check) {
          setcookie('FName', $data['FName'], time()+ 900 ) ;  //cookie expires after 15 mins
          setcookie('LName', $data['LName'], time() + 900 ) ;
          //
          //use session variables instead of cookies
          //these variables should now be available to all pages in the application as long as the users session exists
          $_SESSION['FName'] = $data['FName'];
          $_SESSION['LName'] = $data['LName'];
          $_SESSION['UserName'] = $data['UserName'];
          //to enable $_SESSION array to be populated we always need to call start_session() - this is done in header.php

          //print_r is will print out the contents of an array
          //print_r($_SESSION);
          //
          //Redirect to another page
          $url = absolute_url('Index.php');  //function defined in Loginfunctions.php to give absolute path for required page
          $logged = true;
          //this version of the header function is used to redirect to another page
          header("Location: $url");//since we have entered correct login details we are now being directed to the home page

          exit();
          } else {
          $errors = $data;
          }
          }

          //create a sopace between the button and the error messages
          echo'<div class="spacer"></div>';

          if (!empty($errors)) {
          echo '<br/> <p class="error">The following errors occurred: <br />';

          //foreach is a simplified version of the 'for' loop
          foreach ($errors as $err) {
          echo "$err <br />";
          }

          echo '</p>';
          }

          //this is the end of the <div> that contains the form
          echo '</div>';

          /* */
        ?>
    </div>
</body>

<?php
include 'Footer.php';
?>

2 个答案:

答案 0 :(得分:1)

在PHP代码部分中注释它们

<?php /*  code here will not display in html */ ?>

<!-- code here will be visible (in view source) -->  

如果您的php解释器没有在那里运行,则无法隐藏php代码。

答案 1 :(得分:0)

你在行

中忘记了一个"
echo '<div id = "div_1><h1>Login</h1>';

显然导致它以某种方式继续回应之后发生的事情。

解决方案:在"

之后添加缺少的div_1