session_start()问题

时间:2010-11-16 15:53:53

标签: php session

今天我的一位朋友的留言簿出了问题。我们使用一个小型的面向PHP的留言簿,除了一件事情以外它工作得很好:它已经达到了它的信息限制。

所以我做的是编辑博客文件并更改以下设置: //存储在数据文件中的最大条目   $ max_record_in_data_file = 1800;

我这样做的那一刻,出了点问题。我将文件上传回服务器并获得以下内容:

  

警告:session_start()[function.session-start]:无法发送会话cookie - 已在E中发送的标头(输出从E:\ inetpub \ vhosts \ trilogianocturnus.com \ httpdocs \ guestbook.php:1开始)第95行:\ inetpub \ vhosts \ trilogianocturnus.com \ httpdocs \ guestbook.php

我不知道这是什么,我对php很新,但据我所知,这意味着在session_start

之前浏览器已经调用了某些内容

该页面位于: http://trilogianocturnus.com/guestbook.php

头部前面的代码如下:

<? 
/*-----------------------------------------------------
COPYRIGHT NOTICE
Copyright (c) 2001 - 2008, Ketut Aryadana
All Rights Reserved

Script name : ArdGuest
Version : 1.8
Website : http://www.promosi-web.com/script/guestbook/
Email : aryasmail@yahoo.com.au
Download URL : 
   - http://www.promosi-web.com/script/guestbook/download/
   - http://www.9sites.net/download/ardguest_1.8.zip

This code is provided As Is with no warranty expressed or implied. 
I am not liable for anything that results from your use of this code.
------------------------------------------------------*/

//--Change the following variables

//Title of your guestbook
  $title = "Guestbook Nocturnus";
//Change "admin" with your own password. It's required when you delete an entry
  $admin_password = "***";
//Enter your email here
  $admin_email = "***";
//Your website URL
  $home = "http://www.trilogianocturnus.com/main.html";
//Send you an email when someone add your guestbook, YES or NO
  $notify = "YES";
//Your Operating System
//For Windows/NT user : WIN
//For Linux/Unix user : UNIX
  $os = "WIN";
//Maximum entry per page when you view your guestbook
  $max_entry_per_page = 10;
//Name of file used to store your entry, change it if necessary
  $data_file = "ardgb18.dat";
//Maximum entry stored in data file
  $max_record_in_data_file = 1800;
//Maximum entries allowed per session, to prevent multiple entries made by one visitor
  $max_entry_per_session = 10;
//Enable Image verification code, set the value to NO if your web server doesn't support GD lib
  $imgcode = "YES";
//Color & font setting
  $background = "#000";
  $table_top = "#000";
  $table_content_1a = "#090909";
  $table_content_1b = "#000000";
  $table_content_2a = "#090909";
  $table_content_2b = "#000000";
  $table_bottom = "#000";
  $table_border = "#1f1f1f";
  $title_color = "#9f0000";
  $link = "#9f0000";
  $visited_link = "#9f0000";
  $active_link = "#9f0000";
  $font_face = "verdana";
  $message_font_face = "arial";
  $message_font_size = "2";

//-- Don't change bellow this line unless you know what you're doing

$do = isset($_REQUEST['do']) ? trim($_REQUEST['do']) : "";
$id = isset($_GET['id']) ? trim($_GET['id']) : "";
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$self = $_SERVER['PHP_SELF'];

if (!file_exists($data_file)) {
    echo "<b>Error !!</b> Can't find data file : $data_file.<br>";
 exit;
} else {
 if ($max_record_in_data_file != "0") {
  $f = file($data_file);
  rsort($f);
  $j = count($f);
  if ($j > $max_record_in_data_file) {
   $rf = fopen($data_file,"w");
            if (strtoupper($os) == "UNIX") {
            if (flock($rf,LOCK_EX)) {
                  for ($i=0; $i<$max_record_in_data_file; $i++) {
                      fwrite($rf,$f[$i]);      
         }
                  flock($rf,LOCK_UN);
            }
            } else {
               for ($i=0; $i<$max_record_in_data_file; $i++) {
                  fwrite($rf,$f[$i]);      
            }
         }
   fclose($rf);
  }
 }
}
session_start();
$newline = (strtoupper($os) == "WIN") ? "\r\n" : "\n";
switch ($do) {
case "":
   $record = file($data_file);
   rsort($record);
   $jmlrec = count($record);
?>

我当然删除了密码和电子邮件以确保安全,现在这里是有趣的部分。

这个错误在我改变那个设置的那一刻开始发生,但是如果我试图将它恢复到1800(我将其改为11800以测试它),它仍然给我那个错误。

知道这是什么吗?

留言簿网址为:promosi-web.com/script/guestbook /

4 个答案:

答案 0 :(得分:4)

此错误的最常见原因是在<?

之前添加到文件中

很可能是空格或UTF byte order mark

答案 1 :(得分:1)

<?之后放置你的session_start(),你应该没问题

注意:

要使用基于cookie的会话,必须在向浏览器输出任何内容之前调用session_start()。

http://php.net/manual/en/function.session-start.php

答案 2 :(得分:0)

消息说“输出始于...... \ guestbook.php:1”。因此,该行上的文件中必定存在一些启动输出的内容。

确保在打开<?标记之前没有空格或其他不可见字符(例如BOM)。

答案 3 :(得分:0)

检查您是否有空格或字节顺序标记,您也可以执行

ob_start();在页面的开头和ob_end_flush();最后解决了这个问题。

但IMO检查空间或B.O.M