Jump to content

[SOLVED] filtering PHP message board - pliz stop by and see this & help


worldcomingtoanend

Recommended Posts

i have this code below, how can i code it in such a way that a user will not enter the same name twice.  thanks

<?php
// messages.php
if (isset($_POST['message'])) {
    if (file_exists('messageCount.txt')) {
        $count = fopen('messageCount.txt','r+');
        $n = fread($count,1024);
    }
    else {
        $count = fopen('messageCount.txt','a+');
        $n = 0;
    }
    if (($e = ($n + 1)) <= 10) {
        rewind($count);
        fwrite($count,$e);
        fclose($count);
        $fp = fopen('messages.txt', 'a');
        fwrite($fp, "{$_POST['message']}<br />");
        fclose($fp);
    }
}
readfile('messages.txt');
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
    <input type="text" name="message">
    <input type="submit" value="Namen eingeben">
</form>

 

Umm add a check using stristr ?

 

<?php
// messages.php
if (isset($_POST['message'])) {
    if (file_exists('messageCount.txt')) {
        $count = fopen('messageCount.txt','r+');
        $n = fread($count,1024);
    }
    else {
        $count = fopen('messageCount.txt','a+');
        $n = 0;
    }
    if (($e = ($n + 1)) <= 10) {
        rewind($count);
        fwrite($count,$e);
        fclose($count);
        $fp = fopen('messages.txt', 'a');
        if (stristr($n, $_POST['message']) === false) 
            fwrite($fp, "{$_POST['message']}<br />");
        fclose($fp);
    }
}
readfile('messages.txt');
?>

 

I think that is what you are looking for....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.