Automatically disconnect or disable a PHP messabe board

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!

Moderator: General Moderators

Post Reply
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Automatically disconnect or disable a PHP messabe board

Post 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');
 
?>
 
 
 
nvartolomei
Forum Newbie
Posts: 11
Joined: Tue Jan 06, 2009 3:46 pm

Re: Automatically disconnect or disable a PHP messabe board

Post 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');
 
?>
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Automatically disconnect or disable a PHP messabe board

Post 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
Post Reply