Jump to content

Cannot send session cookie - headers already sent


MidOhioIT
 Share

Recommended Posts

I am confused why I am getting the following error and was wondering if I could get a 2nd pair of eyes..

error:

[29-Jul-2010 20:58:01] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in /home/curren11/public_html/mysite***.com/file_monitor.php on line 2

[29-Jul-2010 20:58:01] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/curren11/public_html/mysite***.com/file_monitor.php:2) in /home/curren11/public_html/mysite***.com/file_monitor.php on line 2


 

Here is the code:

<?php
session_start();

$root_path = realpath(getcwd());
$error_monitor_file = $root_path.'/file_modify.txt';
$hour = date("H");
$today = date("m-d-Y");



     $myFile2 = "file_monitor.php.log";
     $fh3 = fopen($myFile2, 'a');
     $log_msg = "Last ran on: ".$today." at: ".$hour." \n";
     fwrite($fh3, $log_msg);
    

function scan_dir($path)
{	
$out = array();	
$files = opendir($path);	

while ($f = readdir($files))
{	
  $extension = substr($f,-3);
  	  	
   if ($f=='.' or $f=='..' or $extension=='jpg' or $extension=='JPG' or $extension=='png' or $extension=='gif' or $f=='file_monitor.php' or $f=='file_modify.txt' or $f=='file_monitor.php.log' or $f =='error_log'  ) 
     {
	   continue;	
	 }	

  if (is_dir($path.'/'.$f))
    {
	  $out = array_merge($out, scan_dir($path.'/'.$f));
	} 		
  //if  (((!is_dir($path.'/'.$f)) && ($f!='.' or $f!='..' or $extension!='jpg' or $extension!='JPG' or $extension!='png' or $extension!='gif'))
  else
  //  {
	    $out[] = $path. '/'. $f;
	//}
}	

  $_SESSION['all_files'] = $out;
  
return $out;
}

$a = scan_dir(getcwd());

$count_array = count($_SESSION['all_files']);
$loop_count=0;
while($loop_count < $count_array)
{
  // file in directory when was it last changed ?
  $filechange1 = date("m-d-Y-H", filemtime($_SESSION['all_files'][$loop_count]));

// was it chnaged today and have I sent out an alert yet?
if($filechange1 == $today."-".$hour) 							
  {
$fh2 = fopen($error_monitor_file, 'a');
fwrite($fh2, "\n alert, file: ".$_SESSION['all_files'][$loop_count]." was changed today within the last hour ! \n");
    fclose($fh2);
  }
 $loop_count ++;	
 // log file? was it changed this past hour?
 if (file_exists($error_monitor_file))
 {
  	$filechange_log = date("m-d-Y-H", filemtime($error_monitor_file));

		if ( ($loop_count == $count_array ) && ($filechange_log == $today."-".$hour ) )
		{
     		 	email();
    		}	
}				
}

// function for email...
function email()
{
require_once ('class.phpmailer.php');

$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "localhost"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "**c66@***ar.com";  // SMTP username
$mail->Password = "*****"; // SMTP password
$mail->From     = "***@***.com";
$mail->FromName = "Colonial Cottage File Changed";
$mail->AddAddress("email@*****.com"); 

$mail->WordWrap = 50;                              // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); 
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  ="Unauthorized file changed today!";
$mail->Body     =  "" ;

$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
   {
     exit();
   }
}

if ((file_exists($error_monitor_file)) && $hour == "00")
{
   unlink($error_monitor_file);
}
fclose($fh3);
exit();
?>

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.