【发布时间】:2013-02-03 01:14:50
【问题描述】:
我又回来了,尝试创建一个“自定义”博客系统。或者 CMS,正如人们所说的那样。这是我当前的代码:
<?php
//include stuff here
$pid = $_GET['pageid'];
$data = mysql_query("SELECT * FROM entries WHERE id='$pid'") or die("MySQL died.");
mysql_real_escape_string($pid);
while($info = mysql_fetch_array( $data ))
{
if (!empty($info)) {
echo $info['data'];
}
else {
echo 'This page no existo.';
}
}
?>
发生的情况是它没有显示“此页面不存在”。作为'404'文本。 假设有人试图直接输入我的网站但犯了一个错误: 本地主机/博客/?pageid=10 它不显示 404 文本!
我在 MySQL 中有一个名为“data”的行。它由——嗯……博客文章的数据组成。我还有一个名为 ID 的行,它是一个自动增量 ID 系统。 “真实”的工作页面 ID 是 1。
谢谢, RBLXDev.
编辑: $信息的Vardump: 转储:
array (size=10)
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string 'Testing potatoCMS... and the title.' (length=35)
'title' => string 'Testing potatoCMS... and the title.' (length=35)
2 => string 'This is a test.
This is a new line.
This is a cookie.
You are getting fat.
FAT.<br />lol' (length=88)
'data' => string 'This is a test.
This is a new line.
This is a cookie.
You are getting fat.
FAT.<br />lol' (length=88)
3 => string '2013-02-02' (length=10)
'date' => string '2013-02-02' (length=10)
4 => string 'Unspecified' (length=11)
'author' => string 'Unspecified' (length=11)
是的,嗯...我有奇怪的占位符。
【问题讨论】:
-
尝试在该数组中使用您知道存在的索引,例如:!空($info['id'])
-
这只是让 pageid=1 “笔记存在”。
-
也可以考虑proper escaping for SQL context,或者使用更方便的prepared statements。
-
哦,我刚刚发现我有一个SQL注入漏洞。在代码中。
-
你能在 $info 上做一个 var_dump 吗?
标签: php mysql content-management-system blogs