Displaying an alert for x amount of hours
<p>I have an alert script in PHP which alerts an app with some sort of emergency text.
Now I need to somehow add some code which will allow an admin to set the alert as a timed alert. Presently they can set the alert and then send another request which will remove the alert.</p>

<p>The code below has been altered to reflect what I currently am using, I have most of it working, except the removal after the time expire, aka the goto a; routine.</p>

<pre><code>$filename = "alertCheck.php";
 $timedalertsingle = $_POST['timedalertsingle'];
 $timedalerthours = $_POST['timedalertchoice'];
 $timestamp = time(); 
 $timedalertseconds = $timedalerthours * 3600;

 // Testing the variables
 echo $timedalertsingle."&lt;br /&gt;";
 echo $timedalerthours."&lt;br /&gt;";
 echo $timestamp."&lt;br /&gt;";
 echo $timedalertseconds."&lt;br /&gt;";
 echo ($timestamp + $timedalertseconds)."&lt;br /&gt;";

// write the file
$fp = fopen ($filename, "w"); 
if ($fp) {
    fwrite ($fp, $timedalertsingle);
    fclose ($fp);
    echo ("&lt;span style='color: #6FF;'&gt;File written:&lt;/span&gt; " . " This alert will last for " .$timedalerthours . " Hour(s)" . "&lt;br /&gt;");
    echo date('m-d-y') ."&lt;br /&gt;";
}
else {
    echo ("File was not written");
}

// test the time
a:
if (time() &gt; ($timestamp + $timedalertseconds)){ 

    // overwrite the file 
    fwrite ($fp);
    fclose ($fp);
    echo ("&lt;span style='color: #6FF;'&gt;There are no alerts.&lt;/span&gt; ");
}
else {
    goto a;
}
</code></pre>

<p>My input (changed to reflect new variable names:</p>

<pre><code>&lt;form action="processtime.php" method="post" name="timedalert"&gt;
&lt;strong&gt;Post a Timed Alert: &amp;nbsp;&amp;nbsp;&lt;/strong&gt;&lt;input name="timedalertsingle" size="60" type="text" /&gt;&lt;br /&gt;
&lt;strong&gt;How many hours this alert will be displayed: &lt;/strong&gt;
&lt;select name="timedalertchoice" /&gt;
  &lt;option value=".0833"&gt;5 Minutes&lt;/option&gt;
  &lt;option selected="selected" value="1"&gt;1 hour&lt;/option&gt;
  &lt;option value="2"&gt;2 hours&lt;/option&gt;
  &lt;option value="4"&gt;4 hours&lt;/option&gt;
  &lt;option value="6"&gt;6 hours&lt;/option&gt;
  &lt;option value="8"&gt;8 hours&lt;/option&gt;
  &lt;option value="12"&gt;12 hours&lt;/option&gt;
  &lt;option value="18"&gt;18 hours&lt;/option&gt;
  &lt;option value="24"&gt;24 hours&lt;/option&gt;
&lt;/select&gt;
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input name="submit" type="submit" value="submit" /&gt;&lt;br /&gt;
&lt;/form&gt;
</code></pre>

<p>So here is what my processtime.php page looks like after this runs:</p>

<p>tree fell half of building 93 is in Cuppertino<br>
24<br>
1354217471<br>
86400<br>
1354303871<br>
File written: This alert will last for 24 Hour(s)<br>
11-29-12    </p>

<p>Problem is that it does not stop the alerts after the given time.
Help! TIA</p>
