He was helped to do this by the usual astonishingly bright and creative crew over there.
Or what if the alert level went down between rebuilds, and the poor reader didn't know he could relax about teror attacks and start being scared witless by SARS and the economy!
Nope. That would never do. So, the only answer was to cook up a PHP version of the terror alert script, so that my site will be up to date ... even if something happens to me. Remember, "just because you're paranoid doesn't mean people aren't out to get you!"
That's a demo in the upper right corner of this entry, and there's another bit of terror business using this script in the left sidebar.
So read on, to see yet another demo and to get the script (this script is a stand-alone - you do not need the plugin):
Okay, well, I realized that I had cooked up a slow, heavy-handed way to "scrape" the DHS site and extract the alert level, so we wouldn't want to invoke it with every hit, nor would we wish to overtax the government server (so to speak). So I threw in a little scratch file that would hold the current information, and allow you to set the time between updates - in the case below, it's four hours, but it's easy to change to a higher or lower frequency.
Just put a blank file named "alert.dat" in the same directory as the script, and chmod it to 777. That way, most of your hits are taking the info from that file and it's very fast. You only scrape the government once every four hours.
Other than that, the script below is very straightforward - the output statements here just echo the alert level and its definition, change the background color to the alert color, and display the graphic image, but you could just as easily make them stylesheet declarations, file pointers, or anything else. I've included the graphics and colors just so you can comment out what you don't want, and use the code for templates for what you do want.
There is a little demo here.
So, if you're into this sort of thing, just copy the PHP below, paste it inline as I did at the beginning of the entry, or in a separate window as above, or make an include, and in any case proceed to scare yourself silly 
<?
$myCheckInt = (60*60*4); //time between checking DHS = 4 hours
$filename = "alert.dat"; //put this empty file in directory, chmod
777
$myURL = "http://www.dhs.gov/dhspublic/display?theme=29&content=320";
$file_last_modified
= filemtime($filename);
$currentTime = time();
$f_pointer = fopen($filename, "r");
$f_read = fread($f_pointer, filesize($filename));
fclose($f_pointer);
if (($currentTime - $file_last_modified) > $myCheckInt || $f_read =="")
{
if (!($siteContent = file($myURL)))
die ("failed to access info!");
foreach($siteContent as $line)
{
if (preg_match("/img name="dhsadvisory"/", $line))
$theLine = $line;
}
$f_pointer = fopen($filename, "w");
fwrite($f_pointer, $theLine);
fclose($f_pointer);
} else {
$theLine = $f_read;}
if (preg_match("/alt="Red Advisory"/",
$theLine))
{
echo "Red Advisory: Severe risk of terrorist attacks.<br><br>";
echo "<img height="40" width="125" border="0" src="dhs-advisory-severe.gif">";
echo "<body bgcolor="#CC0000">";
}
if (preg_match("/alt="Orange Advisory"/", $theLine))
{
echo "Orange Advisory: High risk of terrorist attacks.<br><br>";
echo "<img height="40" width="125" border="0" src="dhs-advisory-high.gif">";
echo "<body bgcolor="#FF9900">";
}
if (preg_match("/alt="Yellow Advisory"/", $theLine))
{
echo "Yellow Advisory: Elevated condition; Significant risk of terrorist attacks.<br><br>";
echo "<img height="40" width="125" border="0" src="dhs-advisory-elevated.gif">";
echo "<body bgcolor="#FFFF00">";
}
if (preg_match("/alt="Blue Advisory"/", $theLine))
{
echo "Blue Advisory: Guarded condition; General risk of terrorist attack.<br><br>";
echo "<img height="40" width="125" border="0" src="dhs-advisory-guarded.gif">";
echo "<body bgcolor="#0033CC">";
}
if (preg_match("/alt="Green Advisory"/", $theLine))
{
echo "Blue Advisory: Low risk of terrorist attacks.<br><br>";
echo "<img height="40" width="125" border="0" src="dhs-advisory-low.gif">";
echo "<body bgcolor="#009900">";
}
?>
Show Comments and Trackbacks Here>>
I can’t get this to work. I keep getting “Warning: stat failed for alert.dat (errno=2 - No such file or directory) in ~home/index.php on line 17” Sorry to be dumb but can you help me?
Posted by on 04/06 at 05:43 AM
Hi, I answered your question over on the forums, but in case you’re checking here first, I think you probably didn’t add the file “alert.dat” to your directory. Just upload a blank text file and set the permissions to 777. Then try the script again. If that doesn’t work, just let me know
Posted by
Oscar on 04/06 at 08:49 AM
department of gratuitous php
fun with terror alerts. & why not?
Tracked on:
: feckless(net) (66.246.77.12) at 2003 04 19 02:04:57
had to come by & say thanks for this - i had quite a bit of fun with it. installed the real thing first, then one thing led to another & now people can come & set their own terror level (& my colors are much prettier
so, thanks again.
Posted by
@feckless on 04/19 at 02:10 AM
Cool! What a beautiful blog you have!
The whole reason I throw together these little scripts is the pleasure in seeing what people like you can do with them.
Posted by
Oscar on 04/19 at 07:48 AM


oijojlo
Posted by
t35t5 on 04/20 at 10:41 AM
Yeah, I am breaking my own rule and commenting on an old entry, but this had me ROTFL!
Posted by
Rori on 01/20 at 03:28 AM
I’ll take comments anywhere I can get ‘em Rori, and I’m glad you enjoyed my little excursion into the world of the “wars on things.”
Posted by
Oscar on 01/20 at 08:36 PM
<<Hide Comments and Trackbacks