检查用户日志问题

时间:2011-08-30 11:23:20

标签: php html

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

1 个答案:

答案 0 :(得分:0)

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

要避免此问题,请确保在index.php的第6行之前包含checkuserlog.php