<?php
//判断用户是否已经登陆
session_start();
if(empty($_SESSION['username']))
{
echo "您还没有登录,请您先登录页面!";
exit;
}
?>
<?phprequire_once('check.php'); //引入公共文件,实现检查用户输入,防止SQL注入漏洞的代码
require_once('db_connect.php'); //引入公共文件,数据库的连接//服务器端的数据有效性验证
//trim()函数可以截取头尾的空白字符
$username = trim($_POST['username']);
$old_pwd = $_POST['old_pwd'];
$new_pwd = $_POST['new_pwd'];//将明文密码使用md5算法加密
$old_pwd = md5($old_pwd);
$new_pwd = md5($new_pwd);if(!empty($username))
{
//建立数据库的连接
$db = db_connect();
//查询数据库,看填写的用户名是否已经存在
$sql = "select * from users
where username='$username' and password='$old_pwd'";
$res = $db->query($sql);
//$res->num_rows 判断上面的执行结果是否含有记录,有记录说明用户名已经存在
if($res->num_rows <= 0)
{
echo "<center><font color='red' size='4'>数据库里不存在该用户!</font></center><br/>";
}
else
{
//将用户信息插入数据库的t_user表
$sql = "update users set password = '$new_pwd'
where username='$username' and password='$old_pwd'";
$res = $db->query($sql);
if(!$res)
{
$db->close(); //关闭数据库
echo '数据库记录修改失败!';
exit;
}
//将输出重定向到register_result.php文件
header("Location: modify_result.php?uid=$username");
}
//关闭数据库连接
$db->close();
}
?>
出现的错误是:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\php\phpnow\htdocs\talking\center.secret-code.php:117) in E:\php\phpnow\htdocs\talking\center.secret-code.php on line 135
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\php\phpnow\htdocs\talking\center.secret-code.php:117) in E:\php\phpnow\htdocs\talking\center.secret-code.php on line 135
//判断用户是否已经登陆
session_start();
if(empty($_SESSION['username']))
{
echo "您还没有登录,请您先登录页面!";
exit;
}
?>
<?phprequire_once('check.php'); //引入公共文件,实现检查用户输入,防止SQL注入漏洞的代码
require_once('db_connect.php'); //引入公共文件,数据库的连接//服务器端的数据有效性验证
//trim()函数可以截取头尾的空白字符
$username = trim($_POST['username']);
$old_pwd = $_POST['old_pwd'];
$new_pwd = $_POST['new_pwd'];//将明文密码使用md5算法加密
$old_pwd = md5($old_pwd);
$new_pwd = md5($new_pwd);if(!empty($username))
{
//建立数据库的连接
$db = db_connect();
//查询数据库,看填写的用户名是否已经存在
$sql = "select * from users
where username='$username' and password='$old_pwd'";
$res = $db->query($sql);
//$res->num_rows 判断上面的执行结果是否含有记录,有记录说明用户名已经存在
if($res->num_rows <= 0)
{
echo "<center><font color='red' size='4'>数据库里不存在该用户!</font></center><br/>";
}
else
{
//将用户信息插入数据库的t_user表
$sql = "update users set password = '$new_pwd'
where username='$username' and password='$old_pwd'";
$res = $db->query($sql);
if(!$res)
{
$db->close(); //关闭数据库
echo '数据库记录修改失败!';
exit;
}
//将输出重定向到register_result.php文件
header("Location: modify_result.php?uid=$username");
}
//关闭数据库连接
$db->close();
}
?>
出现的错误是:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\php\phpnow\htdocs\talking\center.secret-code.php:117) in E:\php\phpnow\htdocs\talking\center.secret-code.php on line 135
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\php\phpnow\htdocs\talking\center.secret-code.php:117) in E:\php\phpnow\htdocs\talking\center.secret-code.php on line 135
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\php\phpnow\htdocs\talking\center.secret-code.php:117) in E:\php\phpnow\htdocs\talking\center.secret-code.php on line 135红色部分有错!