worldcomingtoanend Posted January 7, 2009 Share Posted January 7, 2009 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> Link to comment https://forums.phpfreaks.com/topic/139882-solved-filtering-php-message-board-pliz-stop-by-and-see-this-help/ Share on other sites More sharing options...
premiso Posted January 7, 2009 Share Posted January 7, 2009 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.... Link to comment https://forums.phpfreaks.com/topic/139882-solved-filtering-php-message-board-pliz-stop-by-and-see-this-help/#findComment-731872 Share on other sites More sharing options...
worldcomingtoanend Posted January 7, 2009 Author Share Posted January 7, 2009 premiso - thanks very much it worked. Link to comment https://forums.phpfreaks.com/topic/139882-solved-filtering-php-message-board-pliz-stop-by-and-see-this-help/#findComment-731885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.