Jump to content

Website Alert.


cpugeek

Recommended Posts

i'm currently designing a website and the client wants an alert system, for messages from the site owner.eg. "We are currently doing some scheduled maintenance" or something like that.what i was thinking was to have the file included, and if a variable in the included file was set to true it would echo another variable which would be the message.any ideas on what the code would look like? any and all help is appreciated.please and thank you.:]

Link to comment
Share on other sites

Please clarify: 1. would a "message page" replace the regular page?2. would a "message box" be a constant feature of the regular page?3. would a "message box" appear on the regular page only when a message exists?4. or do you literally mean a javascript alert?

Link to comment
Share on other sites

when the message exists there would be a div at the top with the message in it.when the message does not exist there would be no such div.no javascript alert, i just want text that appears if a variable is set to true.so i'd guess it would be #3.

Link to comment
Share on other sites

Include could work, but then the file containing the message would have to be written by someone who knew php. If that's the case go for it. But the alert could be in a simple text file that anyone could write, save, and delete.So what I'm thinking is this: you have a set of php tags where the alert div should go whenever there is an alert. We know there is an alert because alert.txt will exist in a predefined directory. No file, no alert. So in pseudo code:

<?phpif is_file alert.txt {	$alert_text = get file contents alert.txt 	$alert_text = trim $alert_text //or whatever cleaning up needs to be done	?> <!-- note the curly brace is open -->	BEGIN DIV MARKUP HTML	<?php echo $alert_text ?>	END DIV MARKUP HTML	<?php} ?> <!-- note the closed curly brace -->REST OF DOCUMENT GOES HERE

Of course it gets more complicated if you want to replace a regular item with the alert item.Now if you wanted to go the include route, you could do it like this. First the include file:

<?php$str = "My alert string!";return $str;?>

Now the variation to the above:

<?phpif is_file alert.php {	$alert_text = include alert.php #this only works because of the return statement in the include file	?> <!-- note the curly brace is open -->	BEGIN DIV MARKUP HTML	<?php echo $alert_text ?>	END DIV MARKUP HTML	<?php} ?> <!-- note the closed curly brace -->REST OF DOCUMENT GOES HERE

Link to comment
Share on other sites

thanks for your help it was greatly appreciated, but i found another way to approach it.

<?php$active = "on";if ( $active == "on" ) {$myFile = "/path/to/alert.txt";$fh = fopen($myFile, 'r');$theData = fread($fh, filesize($myFile));fclose($fh);echo $theData;}?>

Link to comment
Share on other sites

What's the point of that? How is that better than what DD suggested:

<?phpif (file_exists('alert.txt'))  echo file_get_contents('alert.txt');?>

That way you don't have to change the code when you don't want the alert to display. You just delete alert.txt. Or rename it.

Link to comment
Share on other sites

i didn't say it was better, but thanks to google i found some of the individual elements of how i wanted it to work and pieced them together.and if it sounded like i was being rude to 'Deirdre's Dad' it was not intentional.have a good day. :]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...