Page 1 of 1
Automatically disconnect or disable a PHP messabe board
Posted: Wed Jan 07, 2009 4:57 am
by tinoda
I have the following simple message board script and how can I automatically disconnect it , lets say after 10 people have entered their comments. Thank you for your help:
Code: Select all
<form>
<input type="text" name="message"><br />
<input type="submit">
</form>
<?php
if (isset($_GET['message']))
{
$fp = fopen('./messages.txt', 'a');
fwrite($fp, "{$_GET['message']}<br />");
fclose($fp);
}
readfile('./messages.txt');
?>
Re: Automatically disconnect or disable a PHP messabe board
Posted: Wed Jan 07, 2009 6:45 am
by nvartolomei
Code: Select all
<form>
<input type="text" name="message"><br />
<input type="submit">
</form>
<?php
if (isset($_GET['message'])) {
if (count(file('./messages.txt')) <= 10) { //file() returns the messages.txt content in array. each line is one index, count() function return the count of indexes in array
$fp = fopen('./messages.txt', 'a');
fwrite($fp, "{$_GET['message']}<br />\n");
fclose($fp);
} else {
echo "We have 10 comments!";
}
}
readfile('./messages.txt');
?>
Re: Automatically disconnect or disable a PHP messabe board
Posted: Wed Jan 07, 2009 7:02 am
by tinoda
nvartolomei wrote:Code: Select all
<form>
<input type="text" name="message"><br />
<input type="submit">
</form>
<?php
if (isset($_GET['message'])) {
if (count(file('./messages.txt')) <= 10) { //file() returns the messages.txt content in array. each line is one index, count() function return the count of indexes in array
$fp = fopen('./messages.txt', 'a');
fwrite($fp, "{$_GET['message']}<br />\n");
fclose($fp);
} else {
echo "We have 10 comments!";
}
}
readfile('./messages.txt');
?>
nvartolomei - thanks very much your code really worked wonders for me. have a happy new year