首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  PHP与模板与代码加密/优化 » [求助]session的问题  


  作者:slopesun
  注册时间:2004-09-07
  主题/回复:58/67
  积分:753
  等级:★★★(六级)
  称号:声名鹊起

  ken.wang@esolux...
  185627321
  www.

 

 发表:2004-10-20 22:39:21 阅读 2763 次 回复 4 次 得分3  |   字号 字色
[求助]session的问题
login.htm
<form name="login" method="post" action="login.php">
  <table width="400" border="1" >
 <tr>
<td><div align="center">用户名:</div></td>
 <td height="30"><input name="name" type="text" id="name"></td>
    </tr>
    <tr>
  <td><div align="center">密码:</div></td>
  <td height="30"><input name="password" type="text" id="password"></td>
    </tr>
    <tr>
  <td> </td>
  <td><input type="submit" name="Submit" value="登陆">
  <input type="reset" name="Submit2" value="重置"></td>
    </tr>
    <tr>
  <td> </td>
  <td height="30"><div align="center">
  <input name="b_submit" type=hidden id="b_submit" value="1"></div></td>
    </tr>
  </table>
</form>


login.php
<?php
session_start();
session_register(sess_iUid);
session_register(sess_sUname);
session_register(sess_bLogin);
if ($b_submit)
{
$sql_db = mysql_connect(localhost,root,123456) or die ("can not connect to the database server");
$sql_conn = mysql_select_db("company", $sql_db) or die ("can not connect to the database");
$sqlSelectUserPasswd = "select * from customer where name='$name' and password=password('$password')";
$sqlQuarSelUserResl = mysql_query($sqlSelectUserPasswd);
if (!$sqlQuarSelUserResl)
{
echo "
<script>
alert('查询失败,请少候');
history.back();
</script>
";
exit;
}
$iCount = mysql_num_rows($sqlQuarSelUserResl);
if (!$iCount)
{
echo "
<script>
alert('无此用户或密码错误');
history.back();
</script>
";
exit;
}
else
{
$arrTem = mysql_fetch_array($sqlQuarSelUserResl);
$sess_iUid = $arrTem[id];
$sess_sUname = $arrTem[name];
$sess_bLogin = true;
Header("Location:user.php");
}
exit;
}

if (!$sess_bLogin)
{
Header("Location:login.php");
}

?>

为什么每次登陆的时候(正确的用湖名和密码)都会有错误提示:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at E:\www\company\login.php:9) in E:\www\company\login.php on line 10

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at E:\www\company\login.php:9) in E:\www\company\login.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at E:\www\company\login.php:9) in E:\www\company\login.php on line 54
 
 1#楼  
 
  回复人:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

   
 1#楼 发表于2004-10-20 22:58:53  评分:1 

你把session_start()放在整个程序的第一行,或者干脆删掉session_start(),就好了
 2#楼  
 
  回复人:garykwan
  注册时间:2005-06-13
  主题/回复:1/2
  积分:407
  等级:★★☆(五级)
  称号:略有小成

用户联系方式已设置为保密
 2#楼 发表于2005-06-15 01:32:35  评分:1 

版主,今天看了这个帖子,我按照你的方法试了一下,又出现了
Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php on line 8

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\Test\login.php on line 51
这个错误,请问这是为什么?
 3#楼  
 
  回复人:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

   
 3#楼 发表于2005-06-21 16:19:43  评分: 

所有的 header() 语句,都必须放在所有输出之前。
比如,任何的html语句,都算输出,PHP里面的  echo  ,print等,都是输出语句。

header() 这样的语句必须放在所有输出之前~~
 4#楼  
 
  回复人:zhanglinye
  注册时间:2005-07-29
  主题/回复:0/2
  积分:402
  等级:★★☆(五级)
  称号:略有小成

   
 4#楼 发表于2005-07-29 21:17:00  评分:1 

把session_start()放在第一行,并且在它的前面最好不要有空格!
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.009sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版