


<html> blah blah blah </html> Content of fwrite() 
Reason7194 wrote:@ OnlyHuman - Partly, I'm never sure to keep all the same topic question, but slightly different, in the same thread or not. If so, I'll delete this and put it in the previous thread on fwrite().
<?php
include("Links.php");
function displayPosts()
{
// make sure file exists, create it otherwise
if( !file_exists("support.php") )
{
$fp = fopen("support.php","w");
fclose($fp);
}
// now open out file for reading
$fp = fopen("support.php", "r");
// ensure valid file
if( $fp )
{
// display each post
while( !feof($fp) )
{
$line = fgets($fp);
$text = htmlentities($line);
if( $text )
echo $text . "<br />";
}
}
// and close
fclose($fp);
}
// FIXED: Case sensitivity mismatch in original $_POST['message'].
if( isset($_POST['message']) && ($_POST['message'] != null) )
{
// this should actually be filtered as well
$message = $_POST['message'];
$fp = fopen("support.php","a");
// a better use of quotes here: Solves the problem of '$message'
// being written to the file instead of the message content and
// appends a new line to each entry.
fwrite($fp, "\n$message");
fclose($fp);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>PUT YOUR PAGE TITLE HERE</title>
</head>
<body>
<form method='post' action=''>
Username:<input name='username' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'></textarea><br />
<input type='submit' />
</form>
<div id="user-content" name="user-content">
<?php displayPosts(); ?>
</div>
</body>
</html>

<?php
include("Links.php");
function displayPosts()
{
// make sure file exists, create it otherwise
if( !file_exists("repost.php") )
{
$fp = fopen("repost.php","w");
fclose($fp);
}
// now open out file for reading
$fp = fopen("repost.php", "r");
// ensure valid file
if( $fp )
{
// display each post
while( !feof($fp) )
{
$line = fgets($fp);
$text = htmlentities($line);
if( $text )
echo "$text <br />";
}
}
// and close
fclose($fp);
}
// FIXED: Case sensitivity mismatch in original $_POST['message'].
if( isset($_POST['message']) && ($_POST['message'] != null) )
{
// this should actually be filtered as well
$message = $_POST['message'];
//Opens the file
$fp = fopen("repost.php","r+");
//Moves the cursor back to beginning of the file. The '0' represents the character location.
fseek($fp,0);
//Writes the content of variable "message" to the pre-specified file.
fwrite($fp, "<br>$message<br />");
fclose($fp);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="menu.css" type="text/css"/>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="Sumry.css" type="text/css" />
<title>Post Area</title>
</head>
<body>
<form method='post' action='supported.php'>
<br>
<br>
<br>
Username:<input name='username' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'></textarea><br />
<input type='submit' />
</form>
</body>
</html> if( isset($_POST['message']) && ($_POST['message'] != null) )
{
// this should actually be filtered as well
$message = $_POST['message'];
//Opens the file
$fp = fopen("repost.php","r+");
//Moves the cursor back to beginning of the file. The '0' represents the character location.
fseek($fp,0);
//Writes the content of variable "message" to the pre-specified file.
fwrite($fp, "<br>$message<br />");
fclose($fp);
}
Return to Interpreted Languages
Users browsing this forum: No registered users and 0 guests