2011-08-30 62 views
0

如果用户未登录,并且他们是用户的个人资料,收件箱和帐户选项,我将使用登录/注册选项创建标题。我在头部顶部使用<?php include_once "../scripts/checkuserlog.php"; ?>,在div中使用<?php echo $logOptions; ?>我希望单词显示出来。我得到的错误是“warning:session_start()[function.session-start]:无法发送会话缓存限制器 - 已经发送的头文件(输出在/home/ssdotcom/public_html/index.php:6开始)在第2行的“/home/ssdotcom/scripts/checkuserlog.php”这对我来说很啰嗦,第二行是一个打开的div标签。 ..这里是头文件中的代码:检查用户日志问题

<?php include_once "../scripts/checkuserlog.php"; ?> 
<div id="header"> 
    <div id="logo"><a href="http://sunnahspace.com/index.php"><img src="../img/logo.jpg" width="500" height="100" alt="SunnahSpace"/></a></div> 
    <div id="header_menu"> 
    <div><?php echo $logOptions; ?></div> 
    </div> 
    <div id="menu_bar"> 
    <div id="menu_text_container"> 
<div class="menu_text"> 
     <span class="menu_text_span"><a href="#">feeds</a></span> 
     </div> 
     <div class="menu_text"> 
     <span class="menu_text_span"><a href="#">blogs</a></span> 
     </div> 
     <div class="menu_text"> 
      <span class="menu_text_span"><a href="#">forums</a></span> 
     </div> 
     <div class="menu_text"> 
     <span class="menu_text_span"><a href="#">chat</a></span> 
     </div> 
     <div class="menu_text"> 
      <span class="menu_text_span"><a href="#">sunnahversity</a></span> 
     </div> 
     <div class="menu_text"> 
     <span class="menu_text_span"><a href="#">suggestions</a></span> 
     </div> 
     <div class="menu_text_right"> 
     <span class="menu_text_span_right"><a href="#">settings</a></span> 
     <span class="menu_text_span_right"><a href="#">about</a></span> 
     <span class="menu_text_span_right"><a href="#">home</a></span> 
     </div> 
    </div> 
</div> 
</div> 

这里是checkuserlog脚本:

<?php 
session_start(); 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
include_once "connect_to_mysql.php"; // Connect to database 
$dyn_www = $_SERVER['HTTP_HOST']; 
$logOptions = ''; 
if (!isset($_SESSION['idx'])) { 
    if (!isset($_COOKIE['idCookie'])) { 
    $logOptions = '<a href="http://' . $dyn_www . '/register.php">Register</a> 
    &nbsp;&nbsp; | &nbsp;&nbsp; 
    <a href="http://' . $dyn_www . '/login.php">Log In</a>'; 
    } 
} 
if (isset($_SESSION['idx'])) { 

    $decryptedID = base64_decode($_SESSION['idx']); 
    $id_array = explode("p3h9xfn8sq03hs2234", $decryptedID); 
    $logOptions_id = $id_array[1]; 

    //private message check: 
    $sql_pm_check = mysql_query("SELECT id FROM private_messages WHERE to_id='$logOptions_id' AND opened='0' LIMIT 1"); 
    $num_new_pm = mysql_num_rows($sql_pm_check); 
    if ($num_new_pm > 0) { 
     $PM_envelope = '<a href="pm_inbox.php"><img src="../img/pm2.gif" width="18" height="11" alt="PM" border="0"/></a>'; 
    } else { 
     $PM_envelope = '<a href="pm_inbox.php"><img src="../img/pm1.gif" width="18" height="11" alt="PM" border="0"/></a>'; 
    } 
    // show results 
    $logOptions = $PM_envelope . ' &nbsp; &nbsp; 
    <!--<a href="http://' . $dyn_www . '">Home</a> 
    &nbsp;&nbsp; |&nbsp;&nbsp; --> 
    <a href="http://' . $dyn_www . '/profile.php?id=' . $logOptions_id . '">Profile</a> 
    &nbsp;&nbsp; |&nbsp;&nbsp; 
    <div class="dc"> 
<a href="#" onclick="return false">Account &nbsp; <img src="../images/darr.gif" width="10" height="5" alt="Account Options" border="0"/></a> 
<ul> 
<li><a href="http://' . $dyn_www . '/edit_profile.php">Account Options</a></li> 
<li><a href="http://' . $dyn_www . '/pm_inbox.php">Inbox Messages</a></li> 
<li><a href="http://' . $dyn_www . '/pm_sentbox.php">Sent Messages</a></li> 
<li><a href="http://' . $dyn_www . '/logout.php">Log Out</a></li> 
</ul> 
</div> 
'; 
//set cookies: 
} else if (isset($_COOKIE['idCookie'])) { 

    $decryptedID = base64_decode($_COOKIE['idCookie']); 
    $id_array = explode("nm2c0c4y3dn3727553", $decryptedID); 
    $userID = $id_array[1]; 
    $userPass = $_COOKIE['passCookie']; 
    // Get their user first name to set into session var 
    $sql_uname = mysql_query("SELECT username, email FROM myMembers WHERE id='$userID' AND password='$userPass' LIMIT 1"); 
    $numRows = mysql_num_rows($sql_uname); 
    if ($numRows == 0) { 
    //kill cookies if set 
     setcookie("idCookie", '', time()-42000, '/'); 
     setcookie("passCookie", '', time()-42000, '/'); 
     header("location: index.php"); 
     exit(); 
    } 
    while($row = mysql_fetch_array($sql_uname)){ 
     $username = $row["username"]; 
     $useremail = $row["email"]; 
    } 

    $_SESSION['id'] = $userID; 
    $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID"); 
    $_SESSION['username'] = $username; 
    $_SESSION['useremail'] = $useremail; 
    $_SESSION['userpass'] = $userPass; 

    $logOptions_id = $userID; 
    mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$logOptions_id'"); 
    $sql_pm_check = mysql_query("SELECT id FROM private_messages WHERE to_id='$logOptions_id' AND opened='0' LIMIT 1"); 
    $num_new_pm = mysql_num_rows($sql_pm_check); 
    if ($num_new_pm > 0) { 
     $PM_envelope = '<a href="pm_inbox.php"><img src="../images/pm2.gif" width="18" height="11" alt="PM" border="0"/></a>'; 
    } else { 
     $PM_envelope = '<a href="pm_inbox.php"><img src="../images/pm1.gif" width="18" height="11" alt="PM" border="0"/></a>'; 
    } 
    // Ready the output for this logged in user 
    $logOptions = $PM_envelope . ' &nbsp; &nbsp; 
    <!--<a href="http://' . $dyn_www . '">Home</a> 
    &nbsp;&nbsp; |&nbsp;&nbsp; --> 
    <a href="http://' . $dyn_www . '/profile.php?id=' . $logOptions_id . '">Profile</a> 
    &nbsp;&nbsp; |&nbsp;&nbsp; 
    <div class="dc"> 
<a href="#" onclick="return false">Account &nbsp; <img src="../images/darr.gif" width="10" height="5" alt="Account Options" border="0"/></a> 
<ul> 
<li><a href="http://' . $dyn_www . '/edit_profile.php">Account Options</a></li> 
<li><a href="http://' . $dyn_www . '/pm_inbox.php">Inbox Messages</a></li> 
<li><a href="http://' . $dyn_www . '/pm_sentbox.php">Sent Messages</a></li> 
<li><a href="http://' . $dyn_www . '/logout.php">Log Out</a></li> 
</ul> 
</div>'; 
} 
?> 

回答

0

线checkuserlog.php 2是在session_start ()。它抱怨的是它不能在头中设置会话cookie,因为某些输出已经从你的index.php发送过来。

为了避免这个问题,请确保您的checkuserlog.php包含的index.php

+0

的6前行这是我的索引的开头: <体风格= “保证金:0;背景色:#333;”>

Nathan

+0

与头部标签的上方,其余当然。 – Nathan

+0

必须在脚本输出任何内容之前调用session_start()。即使你有'echo'“;'某处,那么cookie头文件也不能被发送。将'include_once(... checkuserlog.php)'移到index.php的顶部。看看是否有效。 – arunkumar