【问题标题】:PHP in HTML not working properlyHTML 中的 PHP 无法正常工作
【发布时间】:2016-05-05 12:39:12
【问题描述】:

我的index中有以下代码

<html>
 <head>
  <title>DZ Prototype</title>
<link rel="icon" type="img/ico" href="images/favicon.jpg">
 </head>
 <body>
<center>
<h1>Welcome to DZ Prototype Testing Area!!</h1>
</center>
<p></p>
<p></p>
<p></p>
<p style="text-align:center"><img src="http://images1.knowable.com/live/articles/2_1ec282dc7578c9356aef339b8b98bbe9.gif" alt="It works!!"></p>
<p></p>
<p></p>

<div align="center">
<?php

$theFile = "cowrie.txt";
$line = file($theFile);
echo $line[18];

if (trim($line[18]) == "Incorrectly Classified Instances         1              100      %") { 
    echo "<h2><font color=red>Possible Malicious Login Attempt</h2>";
} else {
    echo "<h2><font color=green>Status Green</h2>";
}

?>
</div>

</body>
</html> 

看来肯定有一个字符混合了整个 php 语法,但不确定是哪一个。

cowrie.txt 仍然需要上传,所以现在 php 中的任何内容都不需要显示,因为没有文件。

【问题讨论】:

  • PHP 出现在 HTML 中。你的主机支持 PHP 吗?
  • 那么如果没有文件怎么回显 $line[18] 呢?
  • 看起来 PHP 在那里不可用
  • @aynber 刚刚检查,显示支持 php 的页面需要在最后重命名为 .php
  • 在比较之前你必须修剪

标签: php html syntax character


【解决方案1】:

您的演示工作正常,所以 PHP 工作正常。必须与您的 courie.txt 文件有关。以下代码可以正常工作(使用模拟的行数组):

<html>
 <head>
  <title>DZ Prototype</title>
<link rel="icon" type="img/ico" href="images/favicon.jpg">
 </head>
 <body>
<center>
<h1>Welcome to DZ Prototype Testing Area!!</h1>
</center>
<p></p>
<p></p>
<p></p>
<p style="text-align:center"><img src="http://images1.knowable.com/live/articles/2_1ec282dc7578c9356aef339b8b98bbe9.gif" alt="It works!!"></p>
<p></p>
<p></p>
<div align="center">
<?php
//$theFile = "cowrie.txt";
//$line = file($theFile);
//echo $line[18];

// Simulated line array for demonstraiton purposes
$line = array("ewfefe", "ewfewfewf", "54g5grthrhryt", "Incorrectly Classified Instances         1              100      %");

if (trim($line[3]) == "Incorrectly Classified Instances         1              100      %") { 
    echo "<h2><font color=red>Possible Malicious Login Attempt</h2>";
} else {
    echo "<h2><font color=green>Status Green</h2>";
}
?>
</div>
</body>
</html> 

【讨论】:

  • 检查你的 courie.txt 文件中是否有特殊字符、制表符、换行符等。比较也会失败,而且它是不可见的。
【解决方案2】:

您的索引文件扩展名看起来像 index.html。将其更改为index.php
使用file_exists()函数

class属性中添加''

if (trim($line[18]) == "Incorrectly Classified Instances 1 100 %") 
{ 
    echo "<h2><font color='red'>Possible Malicious Login Attempt</h2>";
} 
else {
    echo "<h2><font color='green'>Status Green</h2>";
}

所以最终的 Well-Form 代码是

$theFile = "cowrie.txt";

if(file_exists($theFile))
{
    $line = file($theFile);
    echo $line[18];

    if (trim($line[18]) == "Incorrectly Classified Instances 1 100 %") 
    { 
        echo "<h2><font color='red'>Possible Malicious Login Attempt</h2>";
    } 
    else {
        echo "<h2><font color='green'>Status Green</h2>";
    }
}
else{
    echo "File doesn't exist";
}

【讨论】:

    【解决方案3】:

    我的主机 [byethost] 必须将包含 php 的页面命名为 php。所以我所做的就是将 index.html 重命名为 index.php,所以现在它只显示 Green Status,因为该文件不存在并且 trim 函数返回一个 false 值。

    【讨论】:

      【解决方案4】:

      您的代码是正确的。文件是否可用? 使用单一代码进行均衡

      if (trim($line[20]) == '$line = file($theFile);') { 
          echo "<h2><font color=red>Possible Malicious Login Attempt</h2>";
      } else {
          echo "<h2><font color=green>Status Green</h2>";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-15
        • 1970-01-01
        • 2013-11-02
        • 2015-10-20
        • 2015-08-02
        • 1970-01-01
        • 2019-01-13
        相关资源
        最近更新 更多