2011-08-30 65 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