我创建了一个带禁止功能的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.
现在它变得诡异:上面的文字是我脚本中唯一的文字。 "你被禁止了#34;是一些旧的,前alpha文本,但它仍然令人讨厌。 所以为了记录,我很久以前就删除了这个文本。我搜索了每个文件,每个包含和每个数据库。
我甚至已经完成了地图搜索"您已被禁止"句子。没有运气,他找不到任何东西!我还重新启动了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
&amp; 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";
}
?>
答案 0 :(得分:0)
这是一个改进代码的小指南,通过它您可能会发现错误消失或更容易识别:
没有特别的顺序:
运行Error Logging on your PHP !!!认真。这是最初要学习的基础知识之一。
您应该使用HTML5编写,这意味着您的代码需要正确的语法,因此<br/>
变为<br>
并且/>
标记的关闭不需要斜杠。
在HTML中使用正确的属性,<form>
应至少包含enctype
和action
以及accept
属性 。同样地,其他HTML标签可以与更多正确的ettributes相关联。
尝试并避免使用select *
,而是指定您需要选择的每个MySQL列的名称。这是一个更长的啰嗦,但节省了很多“umms&#39;和&#39; aahs&#39;在较大的项目上。
好点:您正在正确转义PHP变量展示位置,并且您正在使用面向对象的数据库连接, 但 您设置数据库查询的方式是非常不安全,应作为优先事项加以改进:
不是直接将变量放入Query字符串,而是将其绑定到查询。 please research this with prejudice(不同的方法取决于您的连接类型)。
从上面的角度来看,你真的应该尽可能地清理输入/ POST数据,永远不要相信任何用户输入。 $_POST
值可以是任何值,因此请使用REGEX清除程序或PHP清除功能从表单和文本输入中删除不需要的/有害的字符。
添加行以查询MySQL命令和feedback errors to your eyes。