Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/
Share on other sites

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.

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>");

     }

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>

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.