论坛: 菜鸟乐园 标题: 关于PHP留言本中文留言会显示乱码问题#8207; 复制本贴地址    
作者: jidanzizi [jidanzizi]    论坛用户   登录
希望能帮忙解决一下,谢谢!页面上中文都可以正常显示,就是留言后的中文出现乱码!
guestbook.txt用作数据库。
guestbook.php代码如下:
<html>
<body>
<!-- 在此之后,可写入任意的HTML代码 作者:陈荣斌 ChenRongbin@gmail.com -->
<?php
// 在以下设置你自己的个人信息
// ========================================
$gbfile = "guestbook.txt"; // 这个文本文件是用来保存留言内容的文件.
$thisfile = "guestbook.php"; // 这个文件名(即本文件的文件名).
$dateshow = "Y-m-d - H:i:s"; // 时间标识形式.
$username = "admin"; // 管理员用户名.
$password = "admin"; // 管理员密码.
$wrongpass = "无法登陆,密码错误!"; // 如果您的密码错识,会出现在的提示.
$wrongname = "无法登陆,用户名错误!"; // 如果您的用户错识,会出现在的提示.
$thankstxt = "<meta http-equiv='refresh' content='3;URL=$thisfile'><p>非常感谢您的留言!<br>您将于3秒自动返回. 如果无法响应,请<a href='$thisfile'>点击此处</a></p>"; // The text that the user will see after entering something in the guestbook.
$errornoname = "<meta http-equiv='refresh' content='3;URL=$thisfile'><p>您未正确填写姓名!<br>您将于3秒自动返回. 如果无法响应,请<a href='$thisfile'>点击此处</a></p>"; // 这些文字是当用户未填写姓名时的提示.
$errornomsg = "<meta http-equiv='refresh' content='3;URL=$thisfile'><p>您未正确填写任何留言信息!<br>您将于3秒自动返回. 如果无法响应,请<a href='$thisfile'>点击此</a></p>"; // 这些文字是当用户未填写留言信息时的提示.
$gbedited = "<meta http-equiv='refresh' content='3;URL=$thisfile'><p>您的留言正在提交!<br>您将于3秒自动返回. 如果无法响应,请<a href='$thisfile'>点击此处</a></p>"; //这些文字是当用户未填写留言信息时的提示.
// ========================================
// Do not change under here
// ========================================
$gbpage = "$_SERVER[PHP_SELF]";
$date = date("$dateshow");
$name = htmlentities(strip_tags($_POST['name']));
$email = htmlentities(strip_tags($_POST['email']));
$homepage = htmlentities(strip_tags($_POST['homepage']));
$message = nl2br(htmlentities(strip_tags($_POST['message'])));
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 75, "<br />", true);
$printfull = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Email:</strong></td><td><a href=\"mailto:$email\">$email</a></td></tr><tr><td><strong>Homepage:</strong></td><td><a href=\"$homepage\" target=\"_blank\">$homepage</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnoemail = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><td><strong>Homepage:</strong></td><td><a href=\"$homepage\" target=\"_blank\">$homepage</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnopage = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Email:</strong></td><td><a href=\"mailto:$email\">$email</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnoemailpage = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
// ========================================
// 代码开始 !!!
// ========================================
switch($_GET['id'])
{
default:
?>
<p align="left"><a href="<?php echo $gbpage; ?>?id=2">管理登陆</a></p>
<table align="center"><form action="<?php echo $gbpage; ?>?id=1" method="post" name="submitform">
<tr><td><strong>姓 名:</strong></td><td><input type="text" name="name" size="50" maxlength="50"></td></tr>
<tr><td><strong>邮 箱:</strong></td><td><input type="text" name="email" size="50" maxlength="50"></td></tr>
<tr><td><strong>网 址:</strong></td><td><input type="text" name="homepage" size="50" maxlength="50" value="http://"></td></tr>
<tr><td valign="top"><strong>信 息:</strong></td><td><textarea name="message" cols="50" rows="7"></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="提交留言"></td></tr>
</form></table><br>
<?php
$gb = file($gbfile);
$gb = array_reverse($gb);
foreach ($gb as $guestbook) { echo stripslashes($guestbook); }
break;
case 1:
if($name == "")
{ echo $errornoname; }
elseif($message == "")
{ echo $errornomsg; }
elseif($email == "")
{
if($homepage == "" || $homepage == "http://")
{
$writeinfo = $printnoemailpage;
$printer = fopen($gbfile,"a");
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
else
{
$writeinfo = $printnoemail;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
}
elseif($homepage == "" || $homepage == "http://")
{
$writeinfo = $printnopage;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
else
{
$writeinfo = $printfull;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
break;
case 2:
?>
<table align="center"><form action="<?php echo $gbpage; ?>?id=3" method="post" name="submitform">
<tr><td><strong>用户名:</strong></td><td><input type="text" name="adminname" size="20"></td></tr>
<tr><td><strong>密  码:</strong></td><td><input type="password" name="adminpass" size="21"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="登陆"></td></tr>
</form></table>
<?php
break;
case 3:
if($_POST["adminname"] == $username) { if($_POST["adminpass"] == $password) {
?>
<table align="center"><form name="guestbookedit" method="post" action="<?php echo $gbpage; ?>?id=4">
<tr><td><textarea name="gbedit" cols="65" rows="30" wrap="off">
<?php
$gb = file("$gbfile");
$gb = array_values($gb);
foreach ($gb as $guestbook) { echo stripslashes($guestbook); }
?>
</textarea></td></tr>
<tr><td>输入管理密码以便保存编辑: <input type="password" name="psw" size="20"></td></tr>
<tr><td><input type="submit" name="Submit" value="保存"><input type="reset" name="Reset" value="重置"></td></tr>
</form></table>
<?php
} else { echo "$wrongpass"; } }
else { echo "$wrongname"; }
break;
case 4:
if($_POST["psw"] == $password)
{
$writeinfo = $_POST['gbedit'];
$writeinfo = stripslashes($writeinfo);
$printer = fopen($gbfile, 'w');
fwrite($printer,$writeinfo);
fclose($printer);
echo $gbedited;
}
else { echo "$wrongpass"; }
break;
}
// ========================================
// 代码结束 !!!
?>
<!-- 在此以上,可写入任意的HTML代码 作者:陈荣斌 ChenRongbin@gmail.com -->
</body>
</html>

地主 发表时间: 11-10-16 01:47

论坛: 菜鸟乐园

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号