开发者

Check user log issue

开发者 https://www.devze.com 2023-03-31 13:17 出处:网络
I\'m creating a header with login/register options if the user is not logged in, and if they are then profile, inbox and account options. I am using <?php include_once \"../scripts/checkuserlog.php

I'm creating a header with login/register options if the user is not logged in, and if they are then profile, inbox and account options. I am using <?php include_once "../scripts/checkuserlog.php"; ?> at the top of the header, with <?php echo $logOptions; ?> in the div I want the words to show up in. The error I am getting is "warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ssdotcom/public_html/index.php:6) in /home/ssdotcom/scripts/checkuserlog.php on line 2" which is jibberish to me, line two is an opening div tag... here is the code for the header file:

<?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>

and here is the checkuserlog script:

<?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='$u开发者_Go百科serID' 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>';
}
?>


Line 2 of checkuserlog.php is session_start(). What it is complaining about is that it is unable to set the session cookie in the header since some output has already been sent from your index.php.

To avoid this problem make sure that your checkuserlog.php is included before line 6 of index.php

0

精彩评论

暂无评论...
验证码 换一张
取 消