开发者

session_start() issue

today one of my friends had a problem with his guestbook. We use a small php orientated guestbook which was working fine except for one thing: it had reached its limit of messages.

So what i did is edit the blog file and change the following setting: //Maximum entry stored in data file $max_record_in_data_file = 1800;

The moment I did this though, something went very wrong. I uploaded the file back on the server and got the following:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\inetpub\vhosts\trilogianocturnus.com\httpdocs\guestbook.php:1) in E:\inetpub\vhosts\trilogianocturnus.com\httpdocs\guestbook.php on line 95

I don't know what this is, I'm very new to php, but from what I understand, it means something is already being called by the browser before session_start

The page is located at: http://trilogianocturnus.com/guestbook.php

The code before the head is as follows:

<? 
/*-----------------------------------------------------
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);
?>

I have of course, removed the password and email for security, now here isthe funny part.

This error started happening the moment i changed that setting up up there, but if i tried to revert it back to 1800 (i changed it to 11800 to test it out), it still gives me that error.

Any idea of what this is?

The guestbook url is: promosi-web.com/script/guestbook/


The most common cause of this error is something being added to the file before the <?

Most likely a space or UTF byte order mark.


Put your session_start() after <? and you should be fine

Note:

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

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


The message says that the “output started at …\guestbook.php:1”. So there must be something in that file on that line that initiated the output.

Make sure that there are no whitespace or other invisible characters (like a BOM) before the opening <? tag.


Check if you have a space or a byte order mark, you can also do an

ob_start(); at the beginning of the page and ob_end_flush(); at the end to solve this issue.

but IMO check for the space or the B.O.M

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜