Hi there,
I need some help with a script... It is obviously a very basic guestbook, but it suit me well. Talking 'well', it runs fine on a local apache, but refuses to do anything on my rented webspace. It just does not do anything. Not even an error message... I've tried a simple script using fwrite to put text into a file, that worked. Please help me.
btw. the page running the guestbook calls urls like template.php?page=guestbook. guestbook calls the content/script named guestbook.php
So, here's the script, that I've strongly modified ;-)
[FONT=Courier New]<?php
/* Guestbook v1.0b Copyright (c) 2001-2002 by Electron
Scripter: Electron
E-Mail: electron@electron-net.org.de
Homepage: www.electron-net.org
*/
$guestbookfile = "guestbook.txt";
if (!file_exists("$guestbookfile")) { echo "ERROR!<br />create file $guestbookfile and chmod 666 the file!"; die(); }
?>
<form action="<?php $PHP_SELF ?>?page=guestbook&add=entry" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td width="80">
Name
</td>
<td>
<input name="name" style="width: 185px; margin-top: 1px;" />
</td>
</tr>
<tr>
<td width="80">
E-Mail
</td>
<td>
<input name="email" style="width: 185px; margin-top: 0px;" />
</td>
</tr>
<tr>
<td width="80">
Homepage
</td>
<td>
<input name="url" value="http://" style="width: 185px; margin-top: 0px;" />
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td align="right">
<textarea type="comment" name="comments" rows="3" style="width: 310px;"></textarea>
<input type="submit" value="Sign" style="text-align: center;" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<table>
<tr>
<td>
<?php
$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
$timer = "$month $mday, $year";
if($add == "entry") {
if($name == "" || $comments == "") { echo "Please enter name and/or comment.<br />"; }
else {
if($url == "http://" || $url == "") {
$url = "</a>none"; }
if($email == "") {
$email = "</a>none";}
$filesize = filesize($guestbookfile);
$file = fopen("$guestbookfile","r");
$buffer = fread($file,$filesize);
fclose($file);
$file = fopen("$guestbookfile","w");
//$parsed_message = strip_tags($comments,"<a>,<i>");
//$comments_br = str_replace("\n","<br>",$parsed_message);
$comments = str_replace("<iframe","<img src=",$comments);
$comments = str_replace("<img src=","<img src=",$comments);
$comments = str_replace("<i>","",$comments);
$comments = str_replace("<meta","<meta",$comments);
$comments = str_replace("<","<",$comments);
$comments = str_replace(">",">",$comments);
$comments = str_replace("|","¦",$comments);
$comments = str_replace("\n","<br />",$comments);
$today = date( "Ymd", time() );
$index = date("YmdHis",time());
$message_table ="$index | $timer | $REMOTE_ADDR | $name | $email | $url | $comments";
fputs($file,"$message_table\n$buffer");
fclose($file);
echo "entry added<br />";
}
}
$data = file("$guestbookfile");
$max = count($data);
$pages = ($max / 10 + 1);
$size = (filesize($guestbookfile) / 1024);
if(filesize($guestbookfile) == 0) { $max = "1"; }
//echo "<center>entries: $max, pages: " . round($pages, 0) . ", size: " . round($size, 2) . "kB<br /></center>";
$msg = 10;
$data = file("$guestbookfile");
rsort ($data);
$max = count($data);
if(!$pg){$pg=0;}
if($pg==0){print("<center>next");}
else {
$tmp = $pg -1;
print("<center><a href=\"$PHP_SELF?page=guestbook&pg=$tmp\">next</a>");
}
$tmp = $pg $msg + $msg;
print(" · ");
if ($max > $tmp){
$tmp = $pg +1;
print ("<a href=\"$PHP_SELF?page=guestbook&pg=$tmp\">back</a></center>");
}
else {print("back</center>");}
$start = $pg $msg;
$end = $pg * $msg + $msg;;
if ($end > $max){$end=$max;}
if(filesize($guestbookfile) == 0) {
print "Guestbook empty...\n";
}
for ($u=$start; $u<$end; $u++)
{
$info = explode("|",$data[$u]);
if($info[7] != "") { $info[7] = "<br /><i>Admin:<br>$info[7]</i>"; }
$info[6] = wordwrap( $info[6], 50, "\n", 1);
$info[3] = wordwrap( $info[3], 50, "\n", 1);
$info[4] = wordwrap( $info[4], 50, "\n", 1);
print
"<hr />
<table>
<tr>
<td>Date</td>
<td>$info[1]</td>
</tr><tr>
<td>Name</td>
<td>$info[3]</td>
</tr><tr>
<td>E-Mail</td>
<td><a href=\"mailto:$info[4]\">$info[4]</a></td>
</tr><tr>
<td>Homepage</td>
<td><a href=\"$info[5]\" target=blank>$info[5]</a></td>
</tr><tr>
<td width=85>Comment</td><td>$info[6] $info[7]</td>
</tr>
</table>\n";
}
echo "</td></tr></table>";
echo "Guestbook (c) 2001-2002 by <a href=\"http://www.electron-net.org\" target=blank>Electron - www.electron-net.org</a>";
?>[/FONT]