检查用户日志问题


Check user log issue

我正在创建一个头与登录/注册选项,如果用户没有登录,如果他们然后配置文件,收件箱和帐户选项。我在标题的顶部使用<?php include_once "../scripts/checkuserlog.php"; ?>,在我想要显示的单词的div中使用<?php echo $logOptions; ?>。我得到的错误是"警告:session_start()[函数。无法发送会话缓存限制器-头已经发送(输出开始于/home/ssdotcom/public_html/index.php:6)在/home/ssdotcom/scripts/checkuserlog.php的第2行"这是jibberish对我来说,第二行是一个开始的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>';
}
?>

checkuserlog.php的第2行是session_start()。它抱怨的是,它无法设置头中的会话cookie,因为一些输出已经从您的index.php发送。

要避免此问题,请确保将checkuserlog.php包含在index.php

的第6行之前