php - 奇怪的问题。出现的句子/脚本不会消失

标签 php mysql

我创建了一个具有禁止功能的 CMS 来禁止违反规则的帐户。

但是,当我禁止某人时,我会禁止用户和我自己。只有当您是管理员时才会显示无样式的文本:

You have been banned.

如果你是被禁止的用户,你会得到

Your account has been disabled and cannot be used anymore.
You find the details below.

Date: 13-04-2016 16:06:27
Reason: Violation of the EULA.

If you have questions, feel free to contact the administrator.

现在它变得令人毛骨悚然:上面的文字是我脚本中唯一的文字。 “你已被禁止”是一些旧的 pre-alpha 文本,但它仍然令人毛骨悚然。 郑重声明,我很久以前就删除了这段文字。我搜索了每个文件、每个包含文件和每个数据库。

我什至在 map 上搜索了“您已被禁止”这句话。倒霉,他什么也找不到!我还重新启动了 XAMPP 和数据库,我也注销并再次登录;也没用。


有关问题的详细信息。

  • 文本完全空白,没有样式或任何内容。

  • 只出现在admin.php

  • 当用户被禁止时出现 - 我仔细检查了禁止脚本,一切运行正常。查询指向正确的数据库等。


因为文字只出现在admin.php中,所以我们需要看一下admin.php。这是一个 520 行的文件。

禁止脚本在最上面:

$sql = "SELECT * FROM bans WHERE user_name='".$_SESSION['user_name']."'";
$result = $conn->query($sql);
if(mysqli_num_rows($result) != 0) {
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $blocked = "
            <div class='modal-inner' style='width:500px'>
            <h2>Account disabled</h2>
            Your account has been disabled and cannot be used anymore.<br />You find the details below.<br /><br />
            Processed: ". $row["user_dateofban"] ."<br />
            Reason: ". $row["reason"] ."<br /><br />
            If you have questions, feel free to contact the administrator.
            </div>
            ";
            exit($blocked);
        }
    }
}

希望有人能帮帮我,这太令人沮丧了!


admin.php

top.php & bot.php 都是 html 文件。没有 php。

<?php
include("loginsys.php");

if ($login->isUserLoggedIn() == true) {

//ban config
$sql = "SELECT * FROM bans WHERE user_name='".$_SESSION['user_name']."'";
$result = $conn->query($sql);
if(mysqli_num_rows($result) != 0) {
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $blocked = "
            <div class='modal-inner' style='width:500px'>
            <h2>Account disabled</h2>
            Your account has been disabled and cannot be used anymore.<br />You find the details below.<br /><br />
            Processed: ". $row["user_dateofban"] ."<br />
            Reason: ". $row["reason"] ."<br /><br />
            If you have questions, feel free to contact the administrator.
            </div>
            ";
            exit($blocked);
        }
    }
}

    if(isset($_SESSION['user_rank']) && $_SESSION['user_rank'] == "3") {
if(isset($_GET["page"]) && $_GET["page"] == "customization") {
    include("assets/top.php");

            if(isset($_POST['editcustom'])) {
                $sql = "UPDATE customization SET iam='".$_POST["iam"]."', iam2='".$_POST["iam2"]."', about='".$_POST["about"]."', about2='".$_POST["about2"]."', about3='".$_POST["about3"]."', recentwork='".$_POST["recentwork"]."', recentwork2='".$_POST["recentwork2"]."', getintouch='".$_POST["getintouch"]."', getintouch2='".$_POST["getintouch2"]."', address='".$_POST["address"]."', phone='".$_POST["phone"]."', email='".$_POST["email"]."', sendbutton='".$_POST["sendbutton"]."', copyright='".$_POST["copyright"]."'";
                $updateuser = $conn->query($sql);
                if ($updateuser) {
                    echo '<div class="alert alert-success">Settings saved.</div>';
                } else {
                    echo '<div class="alert alert-danger">Something went wrong executing the query. Try again.</div>';
                }
            }

    $sql = "SELECT * FROM customization LIMIT 1";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            ?>
<h1>Header</h1>
<form method="post">
<table>
    <tr>
        <td>Header 1</td>
        <td><input type="text" value="<?php echo $row["iam"]; ?>" name="iam" />
    </tr>
    <tr>
        <td>Header 2</td>
        <td><input type="text" value="<?php echo $row["iam2"]; ?>" name="iam2" />
    </tr>
</table>
<h1>About</h1>
<table>
    <tr>
        <td>About heading</td>
        <td><input type="text" value="<?php echo $row["about"]; ?>" name="about" />
    </tr>
    <tr>
        <td>About text</td>
        <td><input type="text" value="<?php echo $row["about2"]; ?>" name="about2" />
    </tr>
    <tr>
        <td>About button</td>
        <td><input type="text" value="<?php echo $row["about3"]; ?>" name="about3" />
    </tr>
</table>
<h1>Recent Work</h1>
<table>
    <tr>
        <td>Recent Work heading</td>
        <td><input type="text" value="<?php echo $row["recentwork"]; ?>" name="recentwork" />
    </tr>
    <tr>
        <td>Recent Work button</td>
        <td><input type="text" value="<?php echo $row["recentwork2"]; ?>" name="recentwork2" />
    </tr>
</table>
<h1>Contact</h1>
<table>
    <tr>
        <td>Heading</td>
        <td><input type="text" value="<?php echo $row["getintouch"]; ?>" name="getintouch" />
    </tr>
    <tr>
        <td>Text</td>
        <td><input type="text" value="<?php echo $row["getintouch2"]; ?>" name="getintouch2" />
    </tr>
    <tr>
        <td>Address</td>
        <td><input type="text" value="<?php echo $row["address"]; ?>" name="address" />
    </tr>
    <tr>
        <td>Phone</td>
        <td><input type="text" value="<?php echo $row["phone"]; ?>" name="phone" />
    </tr>
    <tr>
        <td>Email</td>
        <td><input type="text" value="<?php echo $row["email"]; ?>" name="email" />
    </tr>
    <tr>
        <td>Button text</td>
        <td><input type="text" value="<?php echo $row["sendbutton"]; ?>" name="sendbutton" />
    </tr>
</table>
<h1>Copyright</h1>
<table>
    <tr>
        <td>Copyright</td>
        <td><input type="text" value="<?php echo $row["copyright"]; ?>" name="copyright" />
    </tr>
</table>
<input type="submit" value="Save changes" name="editcustom" />
</form>
            <?php           
        }
    } else {
        echo "No customization yet.";
    }

    include("assets/bot.php");
} else {
?>
<iframe src="admin.php?page=dashboard" style="width:700px;height:500px;">
    Your browser doesn't support iframes. Please upgrade.
</iframe>
<?php
}
    } else {
        echo "Error: No permissions";
    }
} else {
    echo "Error: Not signed in";
}
?>

最佳答案

这是一个改进代码的小指南,通过它您可能会发现错误消失或更容易识别:

排名不分先后:

  • 运行 Error Logging on your PHP !!!严重地。最先学习的基础知识之一。

  • 您应该使用 HTML5 编写,这意味着您的代码需要正确的语法,所以 <br/>变成 <br>/>关闭标签不需要斜线。

  • 在您的 HTML 中使用正确的属性,您的 <form>应该有 enctypeactionaccept属性作为最小值。同样,其他 HTML 标签可以通过关联更多正确的属性来实现。

    • 停止使用 iframe,它们现在不像 XSS 的严重问题那样得到广泛支持。而是使用 CSS 和/或 PHP 包含。
  • 尽量避免使用 select *而是指定您需要选择的每个 MySQL 列的名称。它有点冗长,但在大型项目中节省了很多“嗯”和“啊”。

  • 要点:您正在正确地转义 PHP 变量放置并且您正在使用面向对象的数据库连接,但是您设置数据库查询的方式是非常不安全,应该优先改进:

    • 您不想将变量直接放入查询字符串中,而是希望将其绑定(bind)到查询中。 please research this with prejudice (不同的方法取决于您的连接类型)。

    • 从上面的观点出发,您真的、真的应该尽可能多地清理您的输入/POST 数据,永远不要相信任何用户输入,永远$_POST values 可以是任何东西,所以使用 REGEX 清理器或 PHP 清理函数从表单和文本输入中删除不需要的/破坏性的字符。

  • 添加行以查询您的 MySQL 命令和 feedback errors to your eyes .

关于php - 奇怪的问题。出现的句子/脚本不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36602421/

相关文章:

php - 从 PHP 回显 javascript

PHP组合两个或多个数组

PHP 错误未定义属性:CodeIgniter 2 中的 stdClass::$barang

php - Styles.php 有条件的 PHP/CSS 在 IE 9 中不工作

php - 使用 PHP 从 Mysql 发送 Json 数据

javascript - Ajax - 从 PHP 加载表后调用 AJAX 函数

php - 一个完整的php项目在线调试器

mysql - 如何通过 PhpMyAdmin 在 mysql 数据库中插入希腊文本

mysql - 从表中选择行,其中具有相同 ID 的另一个表中的行在另一列中具有特定值

mysql - 实现大学小组学习的数据库方案