会话和标头相关的错误

时间:2016-04-01 06:36:00

标签: php session header

我创建了一个用户面板,当用户注册并登录时,该面板可以访问。一切正常,但是当我想退出用户面板时,会出现这些错误:

注意:会话已经启动 - 忽略第2行的C:\ xampp \ htdocs \ eshop \ userpanel_exit.php中的session_start()

警告:无法修改标题信息 - 已在第4行的C:\ xampp \ htdocs \ eshop \ userpanel_exit.php中发送的标题(输出从C:\ xampp \ htdocs \ eshop \ top.php:230开始)< / p>

警告:无法修改标题信息 - 已在第5行的C:\ xampp \ htdocs \ eshop \ userpanel_exit.php中发送的标题(输出从C:\ xampp \ htdocs \ eshop \ top.php:230开始)< / p>

我的退出部分代码:

**

<?php
session_start();
unset($_SESSION['email']);
setcookie('remember','',time()-3600,'/');
header('location:login.php');
?>

**

我的用户界面代码:

<?php
session_start();
if(!isset($_SESSION['email'])){
    if(isset($_COOKIE['remember'])){ $_SESSION['email']=$_COOKIE['remember']; }

    else{ header('location:login.php'); }

}

include('connect.php');

$query="select * from tblusers where email='".$_SESSION['email']."' ";
$stmt=$db->prepare($query);
$stmt->execute();

$myresult=$stmt->fetch(PDO::FETCH_ASSOC);

$userid=$myresult['id'];

$fname=$myresult['fname'];
$lname=$myresult['lname'];
$email=$myresult['email'];
$sex=$myresult['sex'];
$pwd=$myresult['password'];
$state=$myresult['state'];
$city=$myresult['city'];
$mobile=$myresult['mobile'];
$tel=$myresult['tel'];
$postalcode=$myresult['postalcode'];
$address=$myresult['address'];
$imgaddress=$myresult['imgaddress'];
$emailnews=$myresult['emailnews'];
$smsnews=$myresult['smsnews'];

$item='info';

if(isset($_GET['item'])){$item=$_GET['item'];} 


?>


<!doctype html>
<html>
<head>
<meta charset="utf-8">

<title> 
<?php

switch($item){

    case 'info': echo 'مشخصات';
    break;
    case 'orders':echo 'سفارشات';
    break;
    case 'msg':echo 'پیغام ها';
    break;
    case 'chpass':echo 'تغییر رمز عبور';
    break;
    case 'exit':echo 'خروج';
    break;

}

?>


</title>

<link rel="stylesheet" href="css/maincss.css" >
<script src="js/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" href="css/jquery.fileupload.css">

<link rel="stylesheet" href="css/bootstrap.min.css">

<style>
#man{ <?php if($sex==1){  ?>  background-position:0px 11px;   <?php } ?> }
#woman{ <?php if($sex==0){  ?>  background-position:0px 11px;   <?php } ?> }


</style>


</head>

<body>

<?php 

include('top.php');

?>
<style>
#undermenu{height:auto; float:right;}
</style>


<div id="undermenu">

    <div id="undermenu1">

    <div id="col-right-parent">

    <div id="col-right">

    <style>
    #myupload img{width:150px; height:150px;}
    </style>

        <h2> تصویر کاربر </h2>

        <div id="myupload" style="width:150px; height:150px; margin:3px auto; background:url(img/person.png)
         center no-repeat;">

         <?php if($imgaddress!=''){ echo '<img src="'.$imgaddress.'"  />' ; }   ?>

         </div><!-- my upload -->

        <?php if($item=='info') { ?>  

        <div id="uperror" style="color:red; text-align:center; vertical-align:middle; margin-bottom:10px;"></div><!-- uploadError-->


        <span style="margin-left:70px; margin-top:5px;" class="btn fileinput-button btn-success">

        <span>انتخاب تصویر</span>

        <input type="file" id="fileupload" name="files[]" multiple>


        </span>

        <div style="width:180px; margin:7px auto; position:relative;opacity:0;" id="progress" class="progress">

        <div id="percent" style="color:#ffffff; width:100%; height:100%; position:absolute; text-align:center; ">
        </div><!--percent-->

        <div class="progress-bar progress-bar-success"></div>

        </div>


<div id="files" class="files" style="display:none;"></div>


        <?php }  else{  ?>


        <style> #col-right{ padding-bottom: 15px; } </style>

               <?php } ?>

    </div> <!-- col-right-->

    <div id="panelmenu">

    <h2> امکانات کاربر</h2> 

        <ul>

        <li><a href="userpanel.php?item=info">مشخصات</a></li>
        <li><a href="userpanel.php?item=orders">سفارشات</a></li>
        <li><a href="userpanel.php?item=msg">پیغام ها</a></li>
        <li><a href="userpanel.php?item=chpass">تغییر رمز عبور</a></li>
        <li><a href="userpanel.php?item=exit">خروج</a></li>

        </ul>


    </div><!-- panel-menu-->



    </div> <!-- col-right-parent-->

    <?php

        switch($item){

        case 'info': include('userpanel_info.php');
        break;
        case 'orders':include('userpanel_orders.php');
        break;
        case 'msg':include('userpanel_msg.php');
        break;
        case 'chpass':include('userpanel_chpass.php');
        break;
        case 'exit':include('userpanel_exit.php');
        break;

        }


    ?>



    <div style="width:740px; height:70px; float:left;"></div>

<script>
.
.
some script
.
.
</script>
<?php

include('uploadscript.php');

?>



    </div><!-- undermenu 1-->

</div> <!-- undermenu -->

<?php

include('basketscript.php');

?>

</body>
</html>

3 个答案:

答案 0 :(得分:0)

开始前检查会话

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

和标题可以帮助您check this

答案 1 :(得分:0)

@Aarony使用

echo "<script> window.location('login.php');</script>";

而不是

header('location:login.php');

答案 2 :(得分:0)

为避免标题错误,请调用此函数:

QGraphicsSvgItem