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!
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:
<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');
?>
<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