Click to See Complete Forum and Search --> : Need help with creating a veeery simple, stripped down "blog."


Jonny123
11-19-2005, 12:31 PM
Hey guys, need your expertise once again...

I'm looking to make (or find and modify if possible) a "blog" of sorts that's completely bare bones. It's for a project I have in mind in which I'm going to be tracking several set factors of my routine on a daily basis, so for our purposes here, say I want to track: Breakfast, Lunch, Dinner, the times of them all and the date.

I'd like to avoid databases or anything like that, simply because I don't know much about them, and if this can be done with php and flat text files, it's probably better for me.

Essentially I'm looking for a php/html page with a form and fields for each of the specified categories. The user plugs in his data, hit's submit and it all tacks on to the same page day after day. Again, nothing fancy at all...I'd like the output to be just one html/php page that continuously grows and grows...

Sound easy enough? Can anyone point me to some scripts that could help (my searches for "blog" scripts gave me too much)? Or some hints at what this code would be like?

Any input is appreciated, thanks in advance! :)

LiLcRaZyFuZzY
11-19-2005, 07:43 PM
i guess it wouldnt be too hard to write, but i don't think that something that specific can be found

shanterusan
11-20-2005, 06:54 PM
I might approach this by using includes (to keep file sizes down) in PHP to store data. Say one file with the parameters you'd call it by (date, title or something) that is included according to entered variables. Is that what you're looking for?

I've seen flat file blogs in use, but offhand I can't remember the addresses. If you want I'll try to find them for you.

Sheldon
11-20-2005, 08:40 PM
This is a very simple script.

//Save them something different than what you save your blank blog file.

<?php

//Sets the page that you can include into yous site layout.
$blog = "blog.php";

if(empty($_GET['action'])){
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=write" method="post">
<textarea name="contents" rows="10" cols="60">
<?php




$fp=fopen($page , "r");

while (!feof($fp)){
$line=fgets($fp);
print stripslashes("$line");
}//end while

fclose($fp);

?>
</textarea><br/><br />



<input type="submit" value="Submit" />
</form>

<?php

}else{

chmod("{$page} , 0777");
$fp=fopen($page , "w");
fputs($fp, $_REQUEST['contents']);


if (fclose($fp)){
print "<h2>File successfully saved</h2>\n";
}else{
print "<h2><font style=\"color:red;\">There was a problem saving the file</font></h2>\n";
}

chmod("{$page} , 0644");

print "<input type=\"button\" value=\"Go Back\" onClick=\"window.location.href='".$_SERVER['PHP_SELF']."';\" />";

}//end if action

?>

SpectreReturns
11-20-2005, 08:43 PM
Seems like a strange way of doing the chmod.

Sheldon
11-20-2005, 08:49 PM
yer proberly is. now you bring it up, delete the chmod part, its the worst way i can think that i would do it.

Jonny123
11-21-2005, 11:45 AM
Thank you for the input guys - the response in these forums are great!

I'm not that great with just eyeing things over, so I'll have to play around with the provided script when I have the chance... I'm sure it'll be enough of a jumping point for me. I
'll follow up with any questions if need be, but hopefully I can just tweak this (if need be) to my liking... :)

Thanks!

Sheldon
11-21-2005, 02:18 PM
If you include it in your pre made pages then you wont need much tweaking except for adding any more feilds.

Do change the layout add more lines like this for different feilds


fputs($fp, $_REQUEST['contents']);

you could make


fputs($fp, "<div id=container>");
fputs($fp, $_REQUEST['name']);
fputs($fp, "<br>");
fputs($fp, $_REQUEST['contents']);
fputs($fp, "</div>");
so forth so on

Jonny123
11-21-2005, 11:03 PM
Ok, the code helped a lot as I assumed...good starting point. Essentially, the provided code (with minor tweaks because it wouldn't work straight as it was posted) does what I want.

However, instead of continually adding to the "blog.php" page, it overwrites it each time with whatever data is in the fields...

Can this code be easily modified to have it add to "blog.php", or do things begin to get more complicated with that?

Keep in mind I am pretty much a newbie to PHP. ;) :(


<body>
<?php
//Sets the page that you can include into yous site layout.
$blog = "blog.php";
$page = $blog;

if(empty($_GET['action'])){
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=write" method="post">
<p>Field 1:<br>
<input name="1" type="text" id="1" size="50">
</p>
<p>Field 2:<br>
<input name="2" type="text" id="2" size="50">
</p>
<p>Field 3:<br>
<textarea name="3" cols="50" rows="10" id="3"></textarea>
<br/>
<br />
<input type="submit" value="Submit" />
</p>
</form>

<?php

}else{

$fp=fopen($page , "w");
fputs($fp, "<div id=container>");
fputs($fp, $_REQUEST['1']);
fputs($fp, "<br>");
fputs($fp, $_REQUEST['2']);
fputs($fp, "<br>");
fputs($fp, $_REQUEST['3']);
fputs($fp, "</div>");

if (fclose($fp)){
print "<h2>File successfully saved</h2>\n";
}else{
print "<h2><font style=\"color:red;\">There was a problem saving the file</font></h2>\n";
}

print "<input type=\"button\" value=\"Go Back\" onClick=\"window.location.href='".$_SERVER['PHP_SELF']."';\" />";

}//end if action

?>

</body>

Sheldon
11-22-2005, 02:14 PM
<?php

}else{

$fp=fopen($page , "a"); // changed this to amend
fputs($fp, "<div id=container>");
fputs($fp, $_REQUEST['1']);
fputs($fp, "<br>");
fputs($fp, $_REQUEST['2']);
fputs($fp, "<br>");
fputs($fp, $_REQUEST['3']);
fputs($fp, "</div>");

if (fclose($fp)){
more codes to use here is amend is not right (http://nz.php.net/fopen)