[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I run cron jobs without errors? ( session_start() : Cannot send session cookie/cache )

Posted on 2009-02-21
56
Medium Priority
?
616 Views
Last Modified: 2013-12-13
I am setting up a cart script with customer follow up emails etc. For running the sequence emails for follow up I need to run cron jobs.

However I get this error running the cron jobs:
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/campaign/campaign.cron.launched.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/smartnco/public_html/campaign/campaign.cron.launched.php:2) in <b>/home/smartnco/public_html/campaign/campaign.cron.launched.php</b> on line <b>2</b><br />

I guess you're curious to see the file, but I guess that's no need for it. You see, I tested also with a very easy file - and got the same error:

File:
<?php session_start(); ?>
<?php echo "test"; ?>

No blanks, nothing but code. And the same error:
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>1</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/smartnco/public_html/campaign/test.php:1) in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>1</b><br />
test


These are the messages sent to me BY EMAIL. If I try to run the files from my browser, they output nothing...Not even a blank.

There's an empty htaccess file in the root. Not in the subfolder.

I'm stuck...

What can the solution be?

Thanks for helping!

Oh: I run on:
Apache version      2.0.63
PHP version      5.2.6
MySQL version      5.0.67-community
0
Comment
Question by:Maxrespons
  • 35
  • 21
56 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701562
Cannot set cookie usually means whitespace or error messages preceded the cookie.

Please post the file that is getting the error, thanks.
0
 

Author Comment

by:Maxrespons
ID: 23701614
This simple code gets the error...

No blanks in before or after (outside) the start and end tags.


<?php session_start(); ?>
<?php echo "test"; ?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701618
That is the entire script - the one that gets the error?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701629
If so, make this change and run it again.
<?php 
error_reporting(E_ALL);
ob_start();
session_start(); ?>
<?php echo "test"; ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701636
Oh.

My cron looks like this:
php  -q /home/smartnco/public_html/campaign/test.php

or like this:
php  -q /home/smartnco/public_html/campaign.cron.launched.php

(The code under here is tha last mentioned file)
<?php
session_start();
require_once("../smarty/Smarty.class.php");
require_once("../config/00config.php");
require_once("../config/english.php");
require_once("../classes/database.class.php");
require_once("../classes/commonfunctions.php");
require_once("../classes/class.phpmailer.php");
	require_once("../classes/class.linktrackingsystem.php");
	
	$sm = new Smarty();
	$sm->setPathForSmarty();
	$ecom_db = new Ecommercedb();
	$ecom_db->openDB();
	$cf = new commonfunctions();
	$mail = new PHPMailer();
	$link = new LinkTrackingSystem();
	$campaign_id = "";
	$message_id = "";
	
	//$sql = "select a.email_address, b.from_name, b.from_email, b.subject, b.reply_to, b.add_unsub_link, b.send_report from ".$CONFIG_TABLE_PREFIX."_auto_campaign_tb a,".$CONFIG_TABLE_PREFIX."_auto_messages_tb b,".$CONFIG_TABLE_PREFIX."_auto_launched_tb c,".$CONFIG_TABLE_PREFIX."_auto_subscribers_tb d where a.id = b.campaign_id and b.id = c.message_id and a.merchant_id = ".$_SESSION["sess_ecommerce_merchant_id"]." and d.id = c.subscriber_id and c.set_date <='".date("Y-m-d H:i:s")."' and b.status = 1 and d.status = 1 and c.launched_status = -1 order by c.set_date";
	$sql = "select a.*,c.id as launched_id, b.subject, b.add_unsub_link, b.message, b.mail_type, d.subs_name, d.subs_email, d.id as subs_id, d.php_sess_id, b.id as message_id  from ".$CONFIG_TABLE_PREFIX."_auto_campaign_tb a,".$CONFIG_TABLE_PREFIX."_auto_messages_tb b,".$CONFIG_TABLE_PREFIX."_auto_launched_tb c,".$CONFIG_TABLE_PREFIX."_auto_subscribers_tb d where a.id = b.campaign_id and b.id = c.message_id and d.id = c.subscriber_id and c.set_date <='".date("Y-m-d H:i:s")."' and a.status = 1 and b.status = 1 and d.status = 1 and c.launched_status = -1 and d.validate = 1  order by c.set_date";
	
	$launched_data = $ecom_db->getData($sql);
	
	//print_r($launched_data);
	if($launched_data !== false)
	{
		//echo "Hello";
		for($x=0;$x<count($launched_data);$x++)
		{
			//$mail->From = $launched_data[$x]["from_email"];
			$handle = $launched_data[$x]["handler_name"];
			$domain_name = $cf->getDomainName();
			$from_email = $handle."@".$domain_name;
			$mail->From = $from_email;
			$mail->FromName = $launched_data[$x]["from_name"];
			
			if($launched_data[$x]["mail_type"] == "2")
			{
				$mail->ContentType = "text/html";
			}
			else
			{
				$mail->ContentType = "text/plain";
			}
			
			//$mail->AddReplyTo($launched_data[$x]["reply_to"]);
			$mail->AddReplyTo($launched_data[$x]["reply_address"]);
			$mail->Sender = $from_email;
			
			$cf->setMailSettings($mail);
			
			/*if($launched_data[$x]["mail_priority"] == "1")
			{
				$mail->Priority = 1;
			}
			else if($launched_data[$x]["mail_priority"] == "2")
			{
				$mail->Priority = 3;
			}
			else if($launched_data[$x]["mail_priority"] == "3")
			{
				$mail->Priority = 5;
			}
			
			if($launched_data[$x]["mail_method"] == "1")
			{
				$mail->Mailer = "mail";
			}
			else if($launched_data[$x]["mail_method"] == "2")
			{
				$mail->Mailer = "smtp";
				$mail->Host = $launched_data[$x]["smtp_server_info"];
				$mail->Port = $launched_data[$x]["smtp_server_port"];
				if($launched_data[$x]["req_autheticate"] == "1")
				{
					$mail->SMTPAuth = true;
					$mail->Username = $launched_data[$x]["smtp_username"];
					$mail->Password = $launched_data[$x]["smtp_password"];
				}
			}
			else if($launched_data[$x]["mail_method"] == "3")
			{
				$mail->Mailer = "sendmail";
				$mail->Sendmail = $launched_data[$x]["sendmail_path"];
			}*/
			
			$launched_data[$x]["message"] =  html_entity_decode($launched_data[$x]["message"]);
			
			$launched_data[$x]["subject"] = html_entity_decode($launched_data[$x]["subject"]);
			
			$matter = $launched_data[$x]["message"];
			$matter = $cf->getCampaignMatter($launched_data[$x]["subs_id"],$launched_data[$x]["message"]);
			$subject = $launched_data[$x]["subject"];
			/*if($launched_data[$x]["mail_type"] == "1")
			{
				if(strpos($matter,"##Unsubscriber Link##") !== false)
				{
					$matter = explode("##Unsubscriber Link##",$matter);
					$matter = "<pre>".$matter[0]."</pre>##Unsubscriber Link##<pre>".$matter[1]."</pre>";	
				}
				else
				{
					$matter = "<pre>".$matter."</pre>";
				}
				if(strpos($matter,"##Link Tracking##") !== false)
				{
					$matter = explode("##Link Tracking##",$matter);
					$matter = $matter[0]."</pre>##Link Tracking##<pre>".$matter[1];
				}
				
			}*/
			if($launched_data[$x]["mail_type"] == "2")
			{
				$matter .= "<img src='".$CONFIG_SERVER_NAME."/campaign/campaign.check.launched.php?id=".$launched_data[$x]["launched_id"]."&sess_id=".$launched_data[$x]["php_sess_id"]."' width = '0' height = '0'>";
			}
			//$matter .= "<img src='".$CONFIG_SERVER_NAME."/campaign/campaign.check.launched.php?subs_id=".$launched_data[$x]["subs_id"]."&sess_id=".$launched_data[$x]["php_sess_id"]."' width = '0' height = '0'>";
			if(isset($launched_data[$x]["add_unsub_link"]) && strtolower($launched_data[$x]["add_unsub_link"]) == "yes" && strpos($matter,"##Unsubscriber Link##") !== false)
			{
				if($launched_data[$x]["mail_type"] == "2")
				{
					$unsub_matter = $CONFIG_SERVER_NAME."/campaign/campaign.unsubscribed.php?id=".$launched_data[$x]["subs_id"]."&php_sess_id=".$launched_data[$x]["php_sess_id"];
					$unsub_matter = "<a href='".$unsub_matter."' target='_blank'>Click here </a>to unsubscribe yourself";
					$matter = str_replace("##Unsubscriber Link##",$unsub_matter,$matter);
				}
				else
				{
					$unsub_matter = $CONFIG_SERVER_NAME."/campaign/campaign.unsubscribed.php?id=".$launched_data[$x]["subs_id"]."&php_sess_id=".$launched_data[$x]["php_sess_id"];
					$unsub_matter = "To unsubscribe click on the following link or type it in the browser. 
".$unsub_matter;
					$matter = str_replace("##Unsubscriber Link##",$unsub_matter,$matter);
				}
			}
			else
			{
				if(strpos($matter,"##Unsubscriber Link##") !== false)
				{
					$matter = str_replace("##Unsubscriber Link##","",$matter);
				}
			}
			
			//$matter = getLinkMatter($matter,$launched_data[$x]["launched_id"],$launched_data[$x]["message_id"],$launched_data[$x]["php_sess_id"]);
			$subject = $cf->getCampaignMatter($launched_data[$x]["subs_id"],$launched_data[$x]["subject"]);
			$mail->Subject = $subject;
			$matter = $link->checkForLinkTags($matter, $launched_data[$x]["merchant_id"],$launched_data[$x]["launched_id"]);
			//echo $matter;
			$mail->Body = $matter;
			$total_chars = strlen($mail->Body);
			//echo htmlentities($matter);
			$mail->AddAddress($launched_data[$x]["subs_email"],$launched_data[$x]["subs_name"]);
			//print_r($mail);
			//die();
			//print_r($mail);
			if($mail->Send())
			{
				//echo "<li>A";
				//echo "Hi";
				$date = date("Y-m-d H:i:s");
				$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_launched_tb set launched_status = 1, launched_date = '".$date."' where id = ".$launched_data[$x]["launched_id"];
				$ecom_db->recordUpdate($sql);
			}
			$mail->ClearAddresses();
			$mail->ClearReplyTos();
		}
	}
	
	/*$sql = "select a.*,b.email_address from ".$CONFIG_TABLE_PREFIX."_auto_messages_tb a,".$CONFIG_TABLE_PREFIX."_auto_campaign_tb b where a.campaign_id = b.id and a.launched = -1 and a.send_after <='".date("Y-m-d H:i:s")."' and a.status = 1 and b.status = 1 and a.message_sequence_type = -1";
	$campaign_data = $ecom_db->getData($sql);
	if($campaign_data !== false)
	{
		for($x=0;$x<count($campaign_data);$x++)
		{
			$sql = "select * from ".$CONFIG_TABLE_PREFIX."_auto_launched_tb where campaign_id = ".$campaign_data[$x]["campaign_id"]." and message_id = ".$campaign_data[$x]["id"];
			$launched_data = $ecom_db->getDataSingleRow($sql);
			if($launched_data === false || $campaign_data[$x]["change_status"] == 1)
			{
				$sql = "insert into ".$CONFIG_TABLE_PREFIX."_auto_launched_tb (campaign_id, message_id, launched_status, totalrecords,launched_date) values(".$campaign_data[$x]["campaign_id"].",".$campaign_data[$x]["id"].",1,0,'".date("Y-m-d H:i:s")."')";
				$launched_id = $ecom_db->recordInsert($sql);
				$launched_status = -1;
				$launched_records = 0;
			}
			else
			{
				$launched_status = $launched_data["launched_status"];
				$launched_id = $launched_data["id"];
				$launched_records = $launched_data["totalrecords"];
				if($launched_status == -1)
				{
					$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_launched_tb set launched_status = 1 where campaign_id = ".$campaign_data[$x]["campaign_id"]." and message_id = ".$campaign_data[$x]["id"];
					$ecom_db->recordUpdate($sql);
				}
			}
			if($campaign_data[$x]["change_status"] == "1")
			{
				$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_messages_tb set change_status = -1 where id = ".$campaign_data[$x]["id"];
				$ecom_db->recordUpdate($sql);
			}
			if($launched_status == -1)
			{
				$sql = "select * from ".$CONFIG_TABLE_PREFIX."_auto_subscribers_tb where campaign_id = ".$campaign_data[$x]["campaign_id"]." and status = 1 and validate = 1 order by id";
				$subscriber_data = $ecom_db->getData($sql);
				if($subscriber_data !== false)
				{
					$from_name = $campaign_data[$x]["from_name"];
					$from_email = $campaign_data[$x]["from_email"];
					$mail->From = $from_email;
					$mail->FromName = $from_name;
					$mail->ContentType = "text/html";
					$mail->AddReplyTo($campaign_data[$x]["reply_to"]);
					$mail->Sender = $campaign_data[$x]["email_address"];
					$mail->Mailer = "smtp";
					for($y=$launched_records;$y<count($subscriber_data);$y++)
					{
						$sql = "select id from ".$CONFIG_TABLE_PREFIX."_auto_launched_details_tb where launched_id = ".$launched_id." and subs_id = ".$subscriber_data[$y]["id"];
						$found = $ecom_db->getDataSingleRecord($sql);
						if($found === false)
						{
							$matter = $cf->getCampaignMatter($subscriber_data[$y]["id"],$campaign_data[$x]["message"]);
							$matter = getLinkMatter($matter,$subscriber_data[$y]["id"],$campaign_data[$x]["id"],$subscriber_data[$y]["php_sess_id"]);
							$subject = $cf->getCampaignMatter($subscriber_data[$y]["id"],$campaign_data[$x]["subject"]);
							if(isset($campaign_data[$x]["add_unsub_link"]) && strtolower($campaign_data[$x]["add_unsub_link"]) == "yes")
							{
								$unsub_matter = $CONFIG_SERVER_NAME."/campaign/campaign.unsubscribed.php?id=".$subscriber_data[$y]["id"]."&php_sess_id=".$subscriber_data[$y]["php_sess_id"];
								$unsub_matter = "<br><br><a href='".$unsub_matter."' target='_blank'>Click here </a>to unsubscribe yourself";
								$matter = str_replace("##Unsubscriber Link##",$unsub_matter,$matter);
							}
							else
							{
								$matter = str_replace("##Unsubscriber Link##","",$matter);
							}
							$matter .= "<img src='../campaign/campaign.check.launched.php?id=".$campaign_data[$x]["id"]."' width = '0' height = '0'>";
							$matter .= "<img src='../campaign/campaign.check.launched.php?subs_id=".$subscriber_data[$y]["id"]."' width = '0' height = '0'>";
							$to_name = $subscriber_data[$y]["subs_name"];
							$to_email = $subscriber_data[$y]["subs_email"];
							$mail->Subject = $subject;
							$mail->Body = $matter;
							$total_chars = strlen($mail->Body);
							$mail->AddAddress($to_email,$to_name);
							if(!$mail->Send())
							{
								$flag = "-1";
								$send_date = "";
								$comments = $MSG_EMAIL_ERROR;
							}
							else
							{
								$flag = "1";	
								$send_date = date("Y-m-d H:i:s");
								$comments = "";
							}
							$mail->ClearAddresses();
							$sql = "insert into ".$CONFIG_TABLE_PREFIX."_auto_launched_details_tb (launched_id,subs_id,mail_send,send_date,comments,total_chars) values(".$launched_id.",".$subscriber_data[$y]["id"].",".$flag.",'".$send_date."','".$comments."',".$total_chars.")";
							$ecom_db->recordInsert($sql);
							$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_launched_tb set totalrecords = totalrecords + 1 where id = ".$launched_id;
							$ecom_db->recordUpdate($sql);
						}
					}
					$mail->ClearReplyTos();
				}
			}
			$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_messages_tb set launched = 1 where id = ".$campaign_data[$x]["id"];
			//echo $sql;
			$ecom_db->recordUpdate($sql);
			if(isset($campaign_data[$x]["send_report"]) && strtolower($campaign_data[$x]["send_report"]) == "yes" && $launched_status == -1 && $campaign_data[$x]["send_report_status"] != 1)
			{
				$mail->ClearAddresses();
				$sql = "select a.*,b.launched_date from ".$CONFIG_TABLE_PREFIX."_auto_campaign_tb a,".$CONFIG_TABLE_PREFIX."_auto_launched_tb b where a.id = b.campaign_id and a.id = ".$campaign_data[$x]["campaign_id"]." and b.message_id = ".$campaign_data[$x]["id"];
				$data = $ecom_db->getDataSingleRow($sql);
				$from_name = $campaign_data[$x]["from_name"];
				$from_email = $campaign_data[$x]["from_email"];
				$mail->Mailer = "smtp";
				$mail->From = $from_email;
				$mail->FromName = $from_name;
				$mail->ContentType = "text/html";
				$subject = "Campaign ".$data["campaign_name"]." Launched: Report";
				$matter = "Hello ".$from_name.",<br> The Campaign ".$data["campaign_name"]." is launched. The details are:<br>Campaign Name: ".$data["campaign_name"]."<br>Message Subject: ".$campaign_data[$x]["subject"]."<br>Send Date(set in message): ".$campaign_data[$x]["send_after"]."<br>Launched Date: ".$data["launched_date"]."<br><br>For More Details, Click on this Link: <a href = '".$CONFIG_SERVER_NAME."/campaign/campaign.message.details.php?message_id=".$campaign_data[$x]["id"]."'>Show Details</a><br><br>Regards,<br>Administration Team";
				$mail->Subject = $subject;
				$mail->Body = $matter;
				$mail->AddAddress($from_email,$from_name);
				$mail->Send();
				$sql = "update ".$CONFIG_TABLE_PREFIX."_auto_messages_tb set send_report_status = 1 where id = ".$campaign_data[$x]["id"];
				//echo $sql;
				$ecom_db->recordUpdate($sql);
			}
		}
	}	
	$ecom_db->closeDB();*/
	
	function getLinkMatter($matter,$launched_id,$message_id,$session_id="")
	{
		global $ecom_db,$CONFIG_TABLE_PREFIX,$CONFIG_SERVER_NAME;
		$new_matter = $matter;
		$sql = "select link_id from ".$CONFIG_TABLE_PREFIX."_auto_messages_tb where id = ".$message_id;
		$link_id = $ecom_db->getDataSingleRecord($sql);
		if($link_id !== false && $link_id !== "0" && strpos($newmatter,"##Link Tracking##") !== false)
		{
			$url = $CONFIG_SERVER_NAME."/campaign/campaign.managelinktrackingsystem.php?id=".$link_id."&launched_id=".$launched_id;
			$new_matter = str_replace("##Link Tracking##",$url,$new_matter);
		}
		else
		{
			$new_matter = str_replace("##Link Tracking##","",$new_matter);
		}
		return $new_matter;
	}
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701660
Try adding ob_start(); to the top of the script, before ANY other PHP statement.  Then run it like a regular script, not a cron job, and do a "view source" on the output.
0
 

Author Comment

by:Maxrespons
ID: 23701672
Error message (in email sent from cron) is mentioned under.

If I run the file from my browser the output is simple "test", without any white spaces...
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>4</b><br />
test

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701702
I now made the script like this under, run it through a browser, and got the source code saying "test"

<?php ob_start(); ?>
<?php
session_start(); ?>
<?php echo "test"; ?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701710
OK, let's try to get to a single test case.  Please post the code for this:

/home/smartnco/public_html/campaign/test.php

And we can work with that one alone.

Thanks, ~Ray
0
 

Author Comment

by:Maxrespons
ID: 23701723
It's the code I just mentioned...

Only session_start and echo test

(May not be appropriate here, but I could show you my screen live... - and give you access to my mouse and keyboard...)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701734
Instead of this, "It's the code I just mentioned..."  please just post it.  I will make a couple of changes and post it back for you.  That way we will know we are looking at the same code and the same line numbers.

Thanks for the offer about the screen.  I do not think I need it yet, but I will keep it in mind.

Best, ~Ray
0
 

Author Comment

by:Maxrespons
ID: 23701748
LOL.
Sorry, see that the comment could be misunderstood ;-)

The code in test.php is thsi attached
<?php session_start(); ?>
<?php echo "test"; ?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701755
OK.  But the error message says something about line 4.  As Spock would say, that does not compute.  Any chance there is a script with that name in a different directory that we are picking up?
0
 

Author Comment

by:Maxrespons
ID: 23701763
Here's the error message for the LAST test.php

(I also moved the file to the root now)
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/smartnco/public_html/test.php:2) in <b>/home/smartnco/public_html/test.php</b> on line <b>2</b><br />
test

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701766
Oh. and I changed the file a little: So line 2 makes sence
<?php
session_start(); ?>
<?php echo "test"; ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701770
no blanks after first <?php
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701782
It looks like there must be a blank line or a carriage return before the start of the script.  Or maybe an invisible character.

Try this variation...

<?php 
error_reporting(E_ALL);
session_start();
echo "test";
die("Done");

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701820
In the browser it shows: "testDone"

In the cron email, it is the same error:
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/smartnco/public_html/test.php:2) in <b>/home/smartnco/public_html/test.php</b> on line <b>2</b><br />
test

I used the code here:

<?php
error_reporting(E_ALL);
session_start();
echo "test";
die("Done"); ?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701828
OK, I think we may be making progress.  Next try...
<?php
ob_start();
error_reporting(E_ALL);
session_start();
echo "test";
die("X"); ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701834
Running file in browser: source code says "testX"

0
 

Author Comment

by:Maxrespons
ID: 23701838
And email says:

<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>4</b><br />
testX

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701868
One more...
<?php
ob_start();
error_reporting(E_ALL);
var_dump($_SESSION);
session_start();
var_dump($_SESSION);
echo "test";
die("X"); ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701874
Ok, now we're on to something may be... ?
  :-)

This is the error message when running from browser:
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>4</b><br />
NULL
array(7) {
  ["sess_ecommerce_admin_id"]=>
  string(5) "admin"
  ["sess_ecom_check_order_id"]=>
  string(0) ""
  ["sess_ecommerce_order_id"]=>
  string(0) ""
  ["sess_ecommerce_campaign_id"]=>
  string(1) "1"
  ["cur_day"]=>
  int(21)
  ["sess_ecommerce_affiliate_id"]=>
  string(1) "2"
  ["sess_ecommerce_merchant_id"]=>
  string(1) "3"
}
testX

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23701885
And this is the error if run in another browser

<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/campaign/test.php</b> on line <b>4</b><br />
NULL
array(0) {
}
testX

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701896
Interesting.  It picked up a session.  I have seen that behavior before.  What did we get from the cron job?
0
 

Author Comment

by:Maxrespons
ID: 23701925
Here's the email form the cron:
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test.php</b> on line <b>4</b><br />
testX

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23701939
Hmm.  How could this be from the same script running as a cron?  There is no var_dump() output in it!
0
 

Author Comment

by:Maxrespons
ID: 23701980
I don't know.

My cron is:
php  -q /home/smartnco/public_html/test.php

My browser opens:
http://domain.com/campaign/test.php

The FTP puts the file insode public_html
0
 

Author Comment

by:Maxrespons
ID: 23701996
I just renamed the file to test1.php

and changed the cron job to reflect that, so no cache could interfere if there is any.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702001
Looks like cron is domain.com/test.php and browser is domain.com/campaign/test.php

Can you check domain.com/test.php from the browser?
0
 

Author Comment

by:Maxrespons
ID: 23702002
My bad...

Wait a minute... :-)
0
 

Author Comment

by:Maxrespons
ID: 23702014
Here's the correct output from the EMAIL (cron):
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>4</b><br />
NULL
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>5</b><br />
array(0) {
}
testX

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702018
And this shows in a browser that has no coockies for that domain:
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>4</b><br />
NULL
array(0) {
}
testX

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702026
One more try
<?php
ob_start();
var_dump($_COOKIE);
error_reporting(E_ALL);
var_dump($_SESSION);
session_start();
var_dump($_SESSION);
echo "test";
die("X"); ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702031
Here's the output from the brwoser with coockie:

array(4) {
  ["cookie_buyer_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_affiliate_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_ad_id"]=>
  string(1) "1"
  ["PHPSESSID"]=>
  string(32) "733cdb2eaa9d57aa47a08c2ed6cc4baa"
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>5</b><br />
NULL
array(7) {
  ["sess_ecommerce_admin_id"]=>
  string(5) "admin"
  ["sess_ecom_check_order_id"]=>
  string(0) ""
  ["sess_ecommerce_order_id"]=>
  string(0) ""
  ["sess_ecommerce_campaign_id"]=>
  string(1) "1"
  ["cur_day"]=>
  int(21)
  ["sess_ecommerce_affiliate_id"]=>
  string(1) "2"
  ["sess_ecommerce_merchant_id"]=>
  string(1) "3"
}
testX

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702048
And here is the email cron:
array(0) {
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>5</b><br />
NULL
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>6</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>6</b><br />
array(0) {
}
testX

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702175
One more test before I ask you to restart the server!
<?php
ob_start();
 
define('COOKIE_LIFE', 60*60*24); // A 24-HOUR DAY IN SECONDS ( = 86,400 )
 
// USE THIS TO MAKE A PERSISTENT COOKIE - DEFINE COOKIE_LIFE IN SECONDS - date('Z') IS UTC OFFSET IN SECONDS
$cookie_expires	= time() + date('Z') + COOKIE_LIFE;
 
// CHOOSE THE COOKIE NAME AND VALUE
$cookie_name 	= 'RAY';
$cookie_value	= 'YES';
 
// MAKE THE COOKIE AVAILABLE TO ALL DIRECTORY PATHS IN THE WWW ROOT
$cookie_path	= '/';
 
// MAKE THE COOKIE AVAILABLE TO ALL SUBDOMAINS - DOMAIN SETTING STARTS WITH DOT - NO WWW, ETC.
$cookie_domain	= ereg_replace('^www', '', strtolower($_SERVER["HTTP_HOST"]));
 
// MAKE THE COOKIE AVAILABLE TO HTTP, NOT JUST HTTPS
$cookie_secure	= FALSE;
 
// HIDE COOKIE FROM JAVASCRIPT
$cookie_http	= TRUE;
 
// SET THE COOKIE
if (setcookie($cookie_name, $cookie_value, $cookie_expires, $cookie_path, $cookie_domain, $cookie_secure, $cookie_http))
{
      echo "<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD \n";
} else {
      echo "<br/>FAILURE!  THE COOKIE WAS NOT SET AS EXPECTED \n";
}
 
 
var_dump($_COOKIE);
error_reporting(E_ALL);
var_dump($_SESSION);
session_start();
var_dump($_SESSION);
echo "test";
die("XYZ"); ?>

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702225
Here's the browser output:
<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD 
array(4) {
  ["cookie_buyer_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_affiliate_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_ad_id"]=>
  string(1) "1"
  ["PHPSESSID"]=>
  string(32) "733cdb2eaa9d57aa47a08c2ed6cc4baa"
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>26</b><br />
NULL
array(7) {
  ["sess_ecommerce_admin_id"]=>
  string(5) "admin"
  ["sess_ecom_check_order_id"]=>
  string(0) ""
  ["sess_ecommerce_order_id"]=>
  string(0) ""
  ["sess_ecommerce_campaign_id"]=>
  string(1) "1"
  ["cur_day"]=>
  int(21)
  ["sess_ecommerce_affiliate_id"]=>
  string(1) "2"
  ["sess_ecommerce_merchant_id"]=>
  string(1) "3"
}
testXYZ

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702236
and here is the cron EMAIL output:
<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD
array(0) {
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>26</b><br />
NULL
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>27</b><br />
array(0) {
}
testXYZ

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702240
Run each script again and let's see if it picks up the cookie I set.  But after that, it's restart-the-server time.
0
 

Author Comment

by:Maxrespons
ID: 23702247
Here's the output for the browser, after 20 "F5" hits...
<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD 
array(5) {
  ["cookie_buyer_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_affiliate_merchant_id"]=>
  string(1) "1"
  ["cook_ecommerce_ad_id"]=>
  string(1) "1"
  ["PHPSESSID"]=>
  string(32) "733cdb2eaa9d57aa47a08c2ed6cc4baa"
  ["RAY"]=>
  string(3) "YES"
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>26</b><br />
NULL
array(7) {
  ["sess_ecommerce_admin_id"]=>
  string(5) "admin"
  ["sess_ecom_check_order_id"]=>
  string(0) ""
  ["sess_ecommerce_order_id"]=>
  string(0) ""
  ["sess_ecommerce_campaign_id"]=>
  string(1) "1"
  ["cur_day"]=>
  int(21)
  ["sess_ecommerce_affiliate_id"]=>
  string(1) "2"
  ["sess_ecommerce_merchant_id"]=>
  string(1) "3"
}
testXYZ

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702254
And here from the email:
<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD
array(0) {
}
<br />
<b>Notice</b>:  Undefined variable: _SESSION in <b>/home/smartnco/public_html/test1.php</b> on line <b>26</b><br />
NULL
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/smartnco/public_html/test1.php</b> on line <b>27</b><br />
array(0) {
}
testXYZ

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702257
So, should I ask the server provider to restart their server?

What is wrong?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702289
@Maxrespons: I don't know what's wrong.  I do not get this symptom on my machine.  Frankly, restarting the server is just a shot in the dark.  

At this point we know that the same script runs differently when it is a CRON job.  Cookies and Sessions are behaving correctly when things are run as non-Cron jobs.  Setcookie() returns true in either scenario, but the cookie is not set in the cron job - and this is normal since there is no browser to keep and return the cookie.

So tell me more about what you expect to find in $_SESSION when your script is running as a cron job?
0
 

Author Comment

by:Maxrespons
ID: 23702323
Frankly I don't know. I'm not good at php coding. I'm setting up a script on "my" server - and the only thing that is not working are the crons.

They for some reason gets these strange errors. Witch in turn makes the cron process not working as wanted.

I've noe made any line of code in there, but I know what the cron is supposed to do:
To check if any of the sequenced emails should run since last time...

I can send you an invite to see my screen, and the rest of the code...
(it's many files, and I can't upload a zip here)
0
 

Author Comment

by:Maxrespons
ID: 23702333
PS:
The only thing I believe the script is looking for is the current date...

That is the only parametre it doesn't find in the database as far as I know...
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702335
Have you tried running it without the session?  I would try that.  You might want to scan the source code for $_SESSION to see if there are any references.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702340
looking for the current date...

Find that in date('c')

Try dropping the session_start() and let's see if it works!
0
 

Author Comment

by:Maxrespons
ID: 23702353
Try seeing my screen:
http://prod2.invitt.com/2962/mlhand 
0
 

Author Comment

by:Maxrespons
ID: 23702364
This is the only one:
".$_SESSION['sess_ecommerce_merchant_id']."

Open in new window

0
 

Author Comment

by:Maxrespons
ID: 23702366
But that makes no sense to me. But I need to show you the code and database to argue why...
0
 

Author Comment

by:Maxrespons
ID: 23702382
Here's the different codes in different SQLs
From the file that is one of the crons...
 
$sql = "select a.*,c.id as launched_id, b.subject, b.add_unsub_link, b.message, b.mail_type, d.subs_name, d.subs_email, d.id as subs_id, d.php_sess_id, b.id as message_id  from ".$CONFIG_TABLE_PREFIX."_auto_campaign_tb a,".$CONFIG_TABLE_PREFIX."_auto_messages_tb b,".$CONFIG_TABLE_PREFIX."_auto_launched_tb c,".$CONFIG_TABLE_PREFIX."_auto_subscribers_tb d where a.id = b.campaign_id and b.id = c.message_id and d.id = c.subscriber_id and c.set_date <='".date("Y-m-d H:i:s")."' and a.status = 1 and b.status = 1 and d.status = 1 and c.launched_status = -1 and d.validate = 1 and a.merchant_id = ".$_SESSION['sess_ecommerce_merchant_id']." order by c.set_date";
 
But I don't know why it asks for merchant_id from the session. It's just not logical. It should run the cron for all merchants, not just one...

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 750 total points
ID: 23702520
Not able to type over there any more, sorry.  I think we established that you do not need the session in the cron job.  That's all I can do right now, and I have to go, but I feel like we made some progress.

best, ~Ray
0
 

Author Comment

by:Maxrespons
ID: 23702527
Thanks Ray :-)
You helped me find some part of the solution :-)

I do hope I get this thing working properly soon!

Thank you!
0
 

Author Closing Comment

by:Maxrespons
ID: 31549636
Thanks Ray! You helped me see some new sides to this strange server / script behavior.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23702536
Thanks for the points - good luck with your project! ~Ray
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question