这个问题原先提问过一次,但是没有回答,只好再次提问一次了。
用户登录的时候SESSION是写入了,值也赋值了。但是跳转到控制面板的时候,却全部都是空的。另外希望回答者不要说session之前不能有输出,echo输出,html输出之类的。因为session_start();我是放在了第一行的,
就在<?php的后面,因为这样会导致网页瘫痪,导致css和div控制不了,所以加了ob_start()。
涉及到的文件
index.php
cp.php----------------
index.php 文件执行流程:判断是否是已经登录的管理员,如果已经登陆了,那么跳转到cp.php控制面板,无任何提示的跳转,否则→判断是否有$_POST,如果有,就执行查询,进行登录验证,如果验证成功就跳转到cp.php控制面板,然后销毁$_POST,如果登录失败,也销毁$_POST,并且重新跳转到index.php。假如没有登录,并且也没有$_POST,那么引入登录表单。
index.php文件源码如下:<?php 
ob_start();
session_start();
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval(trim($_SESSION[adminID]));
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id > 0){
$url='cp.php';
echo jump($url);
exit;
}
ob_end_clean();
if($_POST){
$psw=trim($_POST['psw']);
$name=trim($_POST['name']);
if($psw=='' || $name==''){
$msg='请将表单填写完整';
$url='index.php';
unset($_POST);
exit;
}
$psw=md5($psw);
$SQL="SELECT * FROM `zhidao_admin` WHERE `name` LIKE '$name' AND `psw` LIKE '$psw' LIMIT 0 , 1 ;";
$obj=new sDB();
$r=$obj->select($SQL);
if($r!=false){
$_SESSION[adminID]=$r[id];
$_SESSION[adminName]=addslashes($r[name]);
$_SESSION[adminTime]=time();
if($_SESSION[adminID] && $_SESSION[adminName]){
//$msg='登录成功!';
$url='cp.php';
}else{
$msg='出现错误';
$url='index.php';
}
}else{
$msg='登录失败!';
$url='index.php';
}
print_r($_SESSION);
include $dir.tpl.'alert.htm';
unset($_POST);
exit;
}
include $tpl.'login.htm';
?>
cp.php文件源码如下”
<?php
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval($_SESSION[adminID]);
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id < 1){
$msg='请先登录';
$url='index.php';
echo jump_quick($url,$msg);
exit;
}
include $tpl.'cp.htm';
?>其中的jump_quick();是返回js警告加跳转的代码。
后来因为我看到有人说注册了SESSION不要立即跳转,否则无法成功,所以新建了一个alert.htm文件作为模板放在了木板文件夹里面,文件全部内容如下“<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head><body>
<!--<?php
print <<<EOT
-->
<script language="javascript" type="text/javascript">
var url="${url}";
var msg="${msg}";
window.onload=function(){
if(msg!=''){
alert(msg);
}
if(url!=''){
window.location.href=url;
}else{
window.close();
}
}
</script>
<!--
EOT;
?>-->
</body>
</html>
大家帮我看下,我找了几天了,还是没有把这个问题解决掉。
而十分奇怪的是,前几天用这个还是正常的。
突然间就不能用了。IE临时文件我每次都清,还是没有用。
在网络上面看到有关PHP BOM的方面的,如何才可以解决?
这些文件包括站点内的所有文件编码都是utf-8

解决方案 »

  1.   

    cp.php中需要加session_start()你干脆加到global.php中吧,省得各个页面都加了
      

  2.   

    require $dir.'global.php';//你确认把session_start();放到这个文件了吗?而且是第一行?
      

  3.   

    用EditePlus打开看是否有BOM头!
      

  4.   

    global.php文件源码如下:<?php
    require ('data/config.php');
    require ('class/mysql.php');
    require ('class/func.php');
    require ('class/session.php');
    !defined('tpl') && define('tpl','templates/'.$tpl.'/');
    define('XF_R','/'.basename(dirname(__FILE__)));
    date_default_timezone_set('PRC');
    //将当前的时区设置为 中国时区
    //ini_set('display_errors', 1);
    ini_set('display_errors', 0);
    //error_reporting(E_ALL);
    error_reporting(0);
    $DB=new DB($host,$root,$psw,$db);
    $DB->conn();
    ?>加了之后网页的显示无法控制了,瘫痪了。使用了ob_start();和ob_end_clean();后,那么$obj=new sDB(); 每次要用的时候都要重新写一次,非常不方便。应该是和ob_start();有关。
      

  5.   

    也就是说加session_start()会出现header already sent的错误?
    如果是就很可能是bom头的问题,ultraedit的话另存为的时候,编码选项框不是有个utf-8无bom头的选项么?