当前位置:Gxlcms > PHP教程 > PHP+mysql登陆问题和sesiion问题

PHP+mysql登陆问题和sesiion问题

时间:2021-07-01 10:21:17 帮助过:14人阅读

主页面报错了,错误是:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php:8) in F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php:8) in F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php on line 7


/**********主页面代码classweb.php**************/
精品课程网




精品课程网






}
?>



/**************跳转登陆代码denglu.php*****************/
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
@ $db = mysql_connect('localhost','root','root'); //连接数据库
if (!$db) {
die('Could not connect: ' . mysql_error());
}
//echo '连接成功!';
mysql_select_db('wwj'); //选择数据库文件wwj
//执行SQL 语句
mysql_query("set names utf8");//数据库中是utf8 ,没有“-”.网页中有!!
$sql="select * from pre_common_member where username=$username";
$result=mysql_query($sql);
if($row=mysql_fetch_assoc($result)){
if($row['password']==md5($password)){
$name=$row['username'];
echo"";
session_register('$name');
header('Location:ClassWeb.php');exit();
}
}
echo"";
header('Location:ClassWeb.php');exit();
mysql_free_result($result);
?>

上面的代码有点多,我知道大家看起来很烦,但是我真的不知道怎么搞的了,希望帮忙一下啊,为找不到原因了。谢谢了!!
顺便帮我看一下跳转的登陆页面代码 有没有错误,谢谢了,真的谢谢!!


回复讨论(解决方案)

放在文件开始处

session_start() 之前不能有任何输出

session_start(); 之前不能有任何?出。把session_start(): 放在文件最前可解?此??。

我也试过,放在最前的,可是还是这样错误!!我把 这句话 放第一行 错误提示就是第一行了。 求指教啊!!!


session_start();
?>
改成
@session_start();
?>

有BOM头吧,用编辑器保存为utf-8 无bom格式。

更改文件编码,改成utf-8无bom头

人气教程排行