Heim  >  Artikel  >  Backend-Entwicklung  >  PHP+mysql登陆问题和sesiion问题

PHP+mysql登陆问题和sesiion问题

WBOY
WBOYOriginal
2016-06-23 13:47:42991Durchsuche

主页面报错了,错误是: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**************/
 nbsp;html>

精品课程网


 
  

  
精品课程网

   
     













用户名:
密  码:
 立即注册





 
 
 
欢迎
       echo $_SESSION['name']; ?> 
退出


   }
?> 
  



/**************跳转登陆代码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"<script>alert('登陆成功!')</script>";
  session_register('$name');
  header('Location:ClassWeb.php');exit();
  }
  }
   echo"<script>alert('用户名或密码错误!')</script>";
  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头

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn