关于中文乱码的怪问题,求教。。。

freedom421 2009-10-20 09:29:48
开发环境是zend studio 7.0,apache2.2+php5.2+mysql5.1

一开始没考虑中文乱码的问题,等程序逻辑实现后才想起来,本来一切都好的,我在改变了PHP和HTML文件的存储编码格式为UTF-8后就出了个很怪的问题。。

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>管理员登陆界面</title>
<script type="text/javascript" language="javascript" src="JS/ajax.js"></script>

<script type="text/javascript" language="javascript">
function check(){
var checkform=document.forms[0];
//alert(checkform.username.value);
//alert(checkform.password.value);
if(checkform.username.value==''||checkform.password.value==''){
alert("用户名或密码不能为空!");
}else{
var par="username="+checkform.username.value+"&"+"password="+checkform.password.value;
//alert(par);
sendRequest("post","adminLogin.php","true",test,par,"text");
}
}
function test(result){
alert(result);
if(result=="OK"){
alert("登陆成功");
location.href="adminManager.php";
}else{
//alert(result);
}
}
</script>
</head>
<body>
<form action="adminManager.php" method="get">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>密  码</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input type="button" value="确认" name="submit" onclick="check()" /></td>
<td align="center"><input type="reset" value="重置" name="reset" /></td>
</tr>
</table>
</form>
</body>
</html>

adminLogin.php

<?php
require '../commons/noCache.php';
require '../commons/Constants.php';
require '../dataBase/db_mysql.php';
require 'user.php';

$username=$_POST["username"];
$password=$_POST["password"];
$connDB=new DB(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD,DB_DATABASE);
$conn=$connDB->connect();
$sql="select * from admininfo where username='$username' and password='$password'";
$result=mysql_query($sql,$conn);
$info=mysql_fetch_row($result);
if($info){
session_start();
$user=new User($username,$password);
$_SESSION["user"]=$user;
echo "OK";
}else{
echo "用户名或密码错误!!";
}

?>

大家看到了。。。我的服务器返回的字段是OK,页面的result接收到了这个responseText得到的结果也是OK,但是if(result=="OK")这句总是为假,我也不知道是为什么了。。。还希望高手帮我看看。。。
...全文
132 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yw1386 2009-10-20
  • 打赏
  • 举报
回复
你看一下这个,http://blog.csdn.net/yw1386/archive/2009/10/14/4671845.aspx
,希望有帮助
freedom421 2009-10-20
  • 打赏
  • 举报
回复
顶上去,问题还没解决呢
freedom421 2009-10-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yunfeifan 的回复:]
alert("-" + result + "-");
看看真的输出 -OK-吗?
[/Quote]

真的呢。。输出就是OK,服务器换成中文的“成功”,他也是输出成功2字
freedom421 2009-10-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 foolbirdflyfirst 的回复:]
检查php文件是否含bom头
[/Quote]

怎么检查?
清风闲客 2009-10-20
  • 打赏
  • 举报
回复
关注中……
yunfeifan 2009-10-20
  • 打赏
  • 举报
回复
alert("-" + result + "-");
看看真的输出 -OK-吗?
foolbirdflyfirst 2009-10-20
  • 打赏
  • 举报
回复
检查php文件是否含bom头
freedom421 2009-10-20
  • 打赏
  • 举报
回复
问题解决了。。。。果然是BOM头的问题。。汗死了。。。
foolbirdflyfirst 2009-10-20
  • 打赏
  • 举报
回复
你客户端alert(result.length)是多少?正确应该是2("OK".length)
freedom421 2009-10-20
  • 打赏
  • 举报
回复
关键是他不是乱码。。。就是识别不了。。很奇怪的。。。。在线继续等回复

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧