This is a response to one of 'OnlyHumans' reply in the thread this question was posted in: Since you have posted I have been learning learning and learning about what you wrote. Many of the terms you used such as the eof term I had never heard about haha. What you wrote really helped me understand what I had in my head, the CMS system. However, i now have a related question to what I have added your script. Instead of posting the variable 'message' to the eof, I placed the content of 'message' at the beginning of the file with fseek. My problem though, is that I cannot get a break to occur between posts. I could make a break happen with the eof, so is there something different that you have to do with fseek to use html for things like breaks and new lines? ( Are they the same thing? )
Here is the syntax that you created with the fseek that I added:
- Code: Select all
<?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+");
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>
Here is the actual fseek area:
- Code: Select all
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);
}


