Trium918 Posted March 23, 2007 Share Posted March 23, 2007 Every time a user refreshes this program it creates a duplicate of the last post and adds it to the blog. How can I fix it? Try it out by posting to the blog and then refresh the page. Example: Click here <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"> <? function language_filter($string) { $obscenities = array("curse","word"," foul ","language"); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++) { $stars .= "*"; } $string = eregi_replace($curse_word,$stars,trim($string)); $stars = ""; } } return $string; } if(isset($_POST['content'])) { //Page was submitted if (!$_POST['content']) { //value of content is empty $output = "There was no data entered!"; echo $output; } else { //Content has value $content = $_POST['content']; $info = $_POST['info']; $content = language_filter($content); @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } } ?> </td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/ Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 After the blog is posted re-direct them using get to another page, this will wipe out the post information they entered. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213899 Share on other sites More sharing options...
Trium918 Posted March 23, 2007 Author Share Posted March 23, 2007 Ok, If I Redirect the user will never get a change to view their post. This is another problem that I am having. I am not able to view a post unless the user enters a new post. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213908 Share on other sites More sharing options...
Trium918 Posted March 23, 2007 Author Share Posted March 23, 2007 Where are all those smart php programmers? Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213922 Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Share Posted March 23, 2007 Search google for a timed redirect. There is one on phpfreaks.com aswell! And frost110 is kind smart! Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213924 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Momma always said life is like a box of chocolates...you never know what flavor you are. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213931 Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Share Posted March 23, 2007 :-\ What does that mean? Chocolates + Me = Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213935 Share on other sites More sharing options...
Trium918 Posted March 23, 2007 Author Share Posted March 23, 2007 Ok guys, this is what I am trying to do. I want the user to be able to post to the blog without having to redirect just to clear the cache. Also the user isnt allowed to view the the last post unless they enter a new topic. I want similar to phpfreaks forum. This is for a school project, so I am not able use phpbb or any other forum or blog software. I not able to use a database neither. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213936 Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Share Posted March 23, 2007 How do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213940 Share on other sites More sharing options...
Trium918 Posted March 23, 2007 Author Share Posted March 23, 2007 Please read reply #7 Also the user isnt allowed to view the the last post unless they enter a new topic. Example of my problem: Click Here!!! Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213942 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 So its homework? if you only wan them to post once per blog use: $chk_ip_dup = mysql_query("SELECT * FROM users WHERE ip='{$IP}'"); if (mysql_num_rows($chk_ip_dup)) { exit ("<b><font color=red size=+1>Onlt one post allowed!</font></b>"); } Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213950 Share on other sites More sharing options...
Trium918 Posted March 24, 2007 Author Share Posted March 24, 2007 Its only a text file. There is no database being used. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213960 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 oh :-X Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213962 Share on other sites More sharing options...
cmgmyr Posted March 24, 2007 Share Posted March 24, 2007 why don't you just clear the variables after you write it to the file? $variable = ''; Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-213964 Share on other sites More sharing options...
Trium918 Posted March 24, 2007 Author Share Posted March 24, 2007 Clearing the variable makes since. but where would I insert it. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214039 Share on other sites More sharing options...
MadTechie Posted March 24, 2007 Share Posted March 24, 2007 add <?php fclose($fp); //<--- after this unset($_POST['content']); //<---this ?> Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214043 Share on other sites More sharing options...
Trium918 Posted March 24, 2007 Author Share Posted March 24, 2007 Even when I unset($_POST['content']) I am still getting duplicate posts when the page is refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214048 Share on other sites More sharing options...
MadTechie Posted March 24, 2007 Share Posted March 24, 2007 what about adding a session, to stop them ie <?php session_start(); ?> <form action="" method="post"> <?php $temp = rand(1,1000); echo "<input name='temp' type='hidden' value='$temp' />"; if(($_POST['temp'] != $_SESSION['tmp1']) ) { echo "COOL"; //add entry etc }else{ echo "BAD"; //don't add } $_SESSION['tmp1'] = $_POST['temp']; ?> <input name="" type="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214060 Share on other sites More sharing options...
Trium918 Posted March 24, 2007 Author Share Posted March 24, 2007 Why would there be a random variable? $temp = rand(1,1000); Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214513 Share on other sites More sharing options...
suzzane2020 Posted March 24, 2007 Share Posted March 24, 2007 Insert this header function just after the script to post the topic. header("location:samepage") The header will redirect the user to the same page.and i guess the post data wud be wiped off Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214519 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 the random number is just a quick cheap way of check to see if the current post data has been sent already, its just a sample script and it works Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214534 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 I still having solve my problem with this program. Can anyone help. Please read reply # 7 for an example. Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214800 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 The page cannot be refreshed without resending the information. Click Retry to send the information again, or click Cancel to return to the page that you were trying to view. How can I stop the php program from resending information back to the blog? Example of the code: Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214816 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 Whats wrong with the example i gave, it works fine, their maybe a better solution but still Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214853 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Help me out here. Would $_POST['tmp1'] be $_POST['content']? Quote Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/#findComment-214868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.