time bomb

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

time bomb

Post by ziggy1621 »

back again...

i'm wondering if there is a way to submit a form everyday at a certain time. i.e. I have a form that pulls from an rss feed and I strip some stuff out of it with substr, then submit it to a text file that is displayed on the site.

So I just need to be pointed to a manual or something of the sort on how to write a script that submits the form everyday at "X" o'clock.

thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

google cron.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

feyd wrote:google cron.
k, looking into it... before I get too far, can i do it on shared hosting?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Yes, but check with your host
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

Pimptastic wrote:Yes, but check with your host
works like a dream thanks
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

ok, maybe I lied... I just got the email confirmation that it ran, but the email contains the html from the page i have set to run, its suppossed to submit info to a text file. here is the code for test.php which is the file that I am trying to run a the specified times

Code: Select all

<html><body><form action="textinsert.php" name="form" method="POST"><textarea cols="45" rows="5" name="report">

<? render_news("http://www.surfline.com/rss/region.cfm?alias=cocoabeachcam", false, 'news', 'news2','1'); ?>
</textarea>
</form>
<script type="text/javascript">
   window.onload=document.forms["form"].submit();
</script>
</body></html>
the funtion render_news is in the file as well, just didn't want to overwhelm the page with unneeded code.

But, what is stopping cron from running this script?

thanks,
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

don't have it submit a form via javascript... don't even use a form. Just load the information from wherever you're loading it and then send the email.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

output from the script run by cron is considered error data which is emailed to the registered account. Your output should be stored into the file you are wishing to update.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

feyd wrote:output from the script run by cron is considered error data which is emailed to the registered account. Your output should be stored into the file you are wishing to update.
okay, forgive me, but i'm loosing you. I don't want it to email me, because it will be running this script (to get the surf report to a client's site) everyday. I just want it to submit to a php page that uses substr to remove the link, then fopen to submit it to a text file.

sorry i'm a bit lost.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I had thought you said you were emailing it to yourself... what feyd is saying (I believe) is that ouput from your script is being sent to you by your host in an email... so that's why you got the email. So... eliminate the form... and just have the script extract the information, fopen the file you want to write it to, write the information, close the file... end script. that's it.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

The Ninja Space Goat wrote:I had thought you said you were emailing it to yourself... what feyd is saying (I believe) is that ouput from your script is being sent to you by your host in an email... so that's why you got the email. So... eliminate the form... and just have the script extract the information, fopen the file you want to write it to, write the information, close the file... end script. that's it.
ok, got the file ready, but have a problem with some syntax, i'm trying to set a function to be a variable "$report" so i can substr$report down. here is my code.

Code: Select all

$report=render_news("http://www.surfline.com/rss/region.cfm?alias=cocoabeachcam", false, news, news2,1);
this just displays the output of "render_news". i want the output to become $report

thanks
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

post the code for the function render_news()

probably all you need to do is return the product rather than echo or print, but let's see the function.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

Code: Select all

//$headline_style = 'news';
$headline_style = '';
$detail_style='news2';
$description_style = '';
$feed_url = '';
$show_detail = true;
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$insideimage = true;
$max = 1;
$count = 1;

function render_news($feed_url, $showdetail, $headlinestyle, $detailstyle, $max_headlines=1) {
	global $show_detail, $headline_style, $detail_style, $max, $count, $insideitem, $insideimage;
	$insideitem=false;
	$insideimage=true;
	$count = 0;
	$show_detail = $showdetail;
	$headline_style = $headlinestyle;
	$detail_style = "news2";
	$max=$max_headlines;
	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	$fp = fopen($feed_url,"r")
		   or die("Error reading RSS data.");
	if ($fp) {
		while ($data = fread($fp, 4096))
	   	xml_parse($xml_parser, $data, feof($fp))
			   or die(sprintf("XML error: %s at line %d",  
				   xml_error_string(xml_get_error_code($xml_parser)),  
				   xml_get_current_line_number($xml_parser)));
		fclose($fp);
		} else {
		echo '<span class="'. $detail_style .'">Syndicated content not available</span>';
		}
	
	// Free up memory used by the XML parser
	xml_parser_free($xml_parser);
}


function startElement($parser, $name, $attrs) {
	global $insideitem, $tag, $title, $description, $link, $insideimage;
	if ($insideitem || $insideimage) {
		$tag = $name;
	} 
	if ($name == "ITEM" ) {
		$insideitem = true;
	} 
	if ($name == "IMAGE") {
		$insideimage = true;
		
	}
}

function endElement($parser, $name) {
	global $insideitem, $tag, $title, $description, $link, $insideimage, $show_detail, $headline_style, $detail_style, $count, $max;

	if ($name == "URL") {
		
		$insideimage=false;

	} else if ($name == "ITEM" && $count < $max) {
		$count++;
		printf('<a href="%s" class="'. $headline_style .'" target="_blank">%s</a><br /><br />',trim($link),trim($title));
		if ($show_detail) 
			printf('<span class="'. $detail_style .'">%s</span><br /><br />',trim($description));
		else {
			echo "";
		}
		$title = "";
		echo "";
		$description = "";
		$link = "";
		$insideitem = false;
	} else if ($count >= $max) {
		$title = "";
		$description = "";
		$link = "";
		$insideitem = false;
	}
}

function characterData($parser, $data) {
	global $insideitem, $tag, $title, $description, $link, $insideimage;
	if ($insideimage) {
		switch ($tag) {
			case "URL":
			
			break;
		}
	} 
	if ($insideitem ) {
	switch ($tag) {
		case "TITLE":
		$title .= $data;
		break;
		case "DESCRIPTION":
		$description .= $data;
		break;
		case "LINK":
	if (!is_string($link)) $link="";
		$link .= $data;
		break;
	}
	}
}
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

you need to take all of those echo() and store that output instead... then return the stored out put with the return control.

OR

you can use the Output Control Functions to capture the content into a variable
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

The Ninja Space Goat wrote:you need to take all of those echo() and store that output instead... then return the stored out put with the return control.

OR

you can use the Output Control Functions to capture the content into a variable
not catching you... the only echo with anything in it is for an error... help please
Post Reply