Jump to content

[SOLVED] Why does it do what it does?


Trium918

Recommended Posts

No

 

you need to add the code just after you //Content has value

 

<?php
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
        echo "<input name='temp' type='hidden' value='$temp' />";
        if(($_POST['temp'] != $_SESSION['tmp1']) )
        {
        //the block in Content has value goes here
        	//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);
            }
        }
        $_SESSION['tmp1'] = $_POST['temp'];

?>

 

*untested

This is the code.

 

<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">
<?php

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>

try this :

 

<?php
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
echo 'There was no data entered!';
} else { //Content has value
        $info = $_POST['info'];    
        $content = language_filter($_POST['content']); 
        @$fp = fopen("project4.txt", "a");
        fwrite($fp, $content."\r\n");
	fclose($fp);
	$_SESSION['posted'] = TRUE;
	header( "Location: " .$_SERVER['PHP_SELF'] );
        $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);
    }
} 

?>

<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">
<?php
	if($_SESSION['posted']) {
        @$fp = fopen("project4.txt", "a");
        $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>

*untested

<?php
session_start();
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
echo 'There was no data entered!';
} else { //Content has value
        $info = $_POST['info'];    
        $content = language_filter($_POST['content']); 
        $fp = fopen("project4.txt", "a");
        fwrite($fp, $content."\r\n");
	fclose($fp);
	$_SESSION = 'isset';
	header( "Location: " .$_SERVER['PHP_SELF'] );
    }
} 

?>

<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">
<?php

	if(isset($_SESSION)) {
	echo 'Form was posted';
        $fp = fopen("project4.txt", "a");
        $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);
	unset($_SESSION);
	}
?>



</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type = submit name="submit"></td>
  </tr>
</table>
</form>

*tested

Could someone please explain the code that was

inserted into my code?

 

<?php
session_start(); //Explain
$_SESSION = 'isset';//Explain
header( "Location: " .$_SERVER['PHP_SELF'] );//Explain

if(isset($_SESSION)) {//Explain
echo 'Form was posted';
$fp = fopen("project4.txt", "a");
$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);
unset($_SESSION);//Explain
}
?>

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.