View Full Version : Guestbook posting problem
Irishcash33
01-07-2009, 02:10 AM
Hello,
I built a guest book using a tutorial. When I post a message, an error message pops up then goes away. And the message doesn't post.
Here is a screenshot (http://www.headfirstgraphics.com/ourwedding/error_message.jpg)of the message.
Here is the link to the guestbook (http://www.headfirstgraphics.com/ourwedding/guestbook/guest_book.php).
Can anyone help?
Thanks
We would need to see your code but it looks like...
...ardgb18.dat has to be giving the cdmod 777 permissions/
...the flock function on line 424 had the wrong parameters passed.
...the fclose isn't referring back to the fopen, or the fopen is wrong.
Please post a link to the page on your site that contains the problematic script so we can check it out.
Please include your code so that we can take a look at it, we can't do much without it.
Irishcash33
01-07-2009, 03:21 AM
I gave a link to the page in my first post.
here is the code where I believe the errors are.
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && eregi("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$",$_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipnum = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ipnum = getenv("REMOTE_ADDR");
}
$newdata = "|~|$idx|~|$tgl|~|$vname|~|$vemail|~|$vcomment|~|$vurl|~|$ipnum|~|";
$newdata = stripslashes($newdata);
$newdata .= $newline;
if (!is_spam($newdata)) {
$tambah = fopen($data_file,"ardgb18.dat");
if (strtoupper($os)=="UNIX") {
if (flock($tambah,LOCK_EX)) {
fwrite($tambah,$newdata);
flock($tambah,LOCK_UN);
}
} else {
fwrite($tambah,$newdata);
}
fclose($tambah);
//--send mail
if (strtoupper($notify) == "YES") {
$msgtitle = "Someone signed your guestbook";
$vcomment = str_replace(""","\"",$vcomment);
$vcomment = stripslashes($vcomment);
$vcomment = str_replace("<br>","\n",$vcomment);
$msgcontent = "Local time : $tgl\n\nThe addition from $vname :\n----------------------------\n\n$vcomment\n\n-----End Message-----";
@mail($admin_email,$msgtitle,$msgcontent,"From: $vemail\n");
}
//--clear session
$_SESSION['name'] = "";
$_SESSION['email'] = "";
$_SESSION['url'] = "http://";
$_SESSION['comment'] = "";
$_SESSION['add']++;
$_SESSION['secc'] = "";
redir($self,"Thank you, your entry has been added.");
} else {
redir($self,"Sorry, your entry can't be added into the guestbook.");
}
break;
case "del":
$record = file($data_file);
$jmlrec = count($record);
for ($i=0; $i<$jmlrec; $i++) {
$row = explode("|~|",$record[$i]);
if ($id == $row[1]) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Delete record</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="<?=$background?>" style="font-family:<?=$font_face?>">
<div align="left">
<font size="4" color="<?=$title_color?>">Delete Confirmation</font>
<br><br>
<table border="0" cellpadding="5" cellspacing="1" width="450">
<tr>
<td bgcolor="<?=$table_top?>">
<font size="2">
<font size="1"><b><?=$row[2]?></font><br><?=$row[3]?></b> - <a href="mailto:<?=$row[4]?>"><?=$row[4]?></a>
<br><br><?=$row[5]?>
<br><br><font size="1">IP : <?=$row[7]?></font>
</font>
</td>
</tr>
</table>
<form action="<?=$self?>" method="post">
<input type="hidden" name="do" value="del2">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="page" value="<?=$page?>">
<font color="<?=$title_color?>" size="2"><b>Admin password : </b></font> <input type="password" name="pwd">
<br><br>
<font size="2" color="<?=$title_color?>"><b>»</b><input type="checkbox" name="byip" value="<?=$row[7]?>"> Delete all records that using this IP : <?=$row[7]?></font>
<br><br>
<input type="submit" value="Delete"> <input type="button" value="Cancel" onClick="window.location='<?="$self?page=$page"?>'">
</form>
</div>
</body>
</html>
<?
}
}
break;
case "del2":
$pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : "";
$id = isset($_POST['id']) ? trim($_POST['id']) : "";
$page = isset($_POST['page']) ? $_POST['page'] : 1;
$byip = isset($_POST['byip']) ? $_POST['byip'] : "";
if ($pwd != $admin_password) {
redir("$self?page=$page","Invalid admin password !");
}
$record = file($data_file);
$jmlrec = count($record);
for ($i=0; $i<$jmlrec; $i++) {
$row = explode("|~|",$record[$i]);
if ($byip == "") {
if ($row[1] == $id) {
$record[$i] = "";
break;
}
} else {
if ($row[7] == $byip) {
$record[$i] = "";
}
}
}
$update_data = fopen($data_file,"w");
if (strtoupper($os) == "UNIX") {
if (flock($update_data,LOCK_EX)) {
for ($j=0; $j<$jmlrec; $j++) {
if ($record[$j] != "") {
fputs($update_data,$record[$j]);
}
}
flock($update_data,LOCK_UN);
}
} else {
for ($j=0; $j<$jmlrec; $j++) {
if ($record[$j] != "") {
fputs($update_data,$record[$j]);
}
}
}
fclose($update_data);
redir("$self?page=$page","Record has been deleted !");
break;
} //--end switch
function redir($target,$msg) {
global $background,$font_face,$title_color;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="refresh" content="1; url=<?=$target?>">
</head>
<body bgcolor="<?=$background?>">
<div align="center"><font color="<?=$title_color?>" face="<?=$font_face?>"><h3><?=$msg?></h3>Please wait...</font></div>
</body>
</html>
<?
exit;
}
function input_err($err_msg,$linkback=true) {
global $background,$font_face;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Error !</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="<?=$background?>">
<div align="center">
<br>
<table border="1" bgcolor="#000000" cellspacing="0" cellpadding="6">
<tr>
<td bgcolor="#FFCC00" align="center">
<font size="3" color="#000000" face="<?=$font_face?>"><b><?=$err_msg?></b><br>
<?if ($linkback) {?>
<font size="2">Click <a href="javascript:history.back()">here</a> and try again.</font>
<?}?>
</font>
</td>
</tr>
</table>
</div>
</body>
</html>
<?
exit;
}
function is_spam($string) {
$data = "spamwords.dat";
$is_spam = false;
if (file_exists($data)) {
$spamword = file($data);
$jmlrec = count($spamword);
for ($i=0; $i<$jmlrec; $i++) {
$spamword[$i] = trim($spamword[$i]);
if (eregi($spamword[$i],$string)) {
$is_spam = true;
break;
}
}
}
return $is_spam;
}
?></p>
Is the above page guest_book.php?
bluewalrus
01-07-2009, 05:21 AM
This is a text version of the error:
Warning: fopen(ardgb18.dat) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 422
Warning: flock() expects parameter 1 to be resource, boolean given in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 424
Warning: fclose(): supplied argument is not a valid stream resource in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\guestbook\guest_book.php on line 431
I could give you a new set of script that writes to a textfile then displays the results back on the main page. You can see it functioning here http://www.travelinchucks.com/qa.php. (this also has a user side panel where they can comment back to comments) This uses 1 text file and 2-4 php pages depends on what functions you want.
Irishcash33
01-07-2009, 03:00 PM
That's sweet Chris!
Is it fully customizable? and easy to implement? Unlike you, I am not a genius with php, I actually know nothing!!!! ha
Thanks
Will
bluewalrus
01-08-2009, 01:38 AM
Yea its real easy....I think and customizable
bluewalrus
01-08-2009, 02:37 AM
You need a txt file with permissions on it set to 777. Then change this "nameofthetextfilegoeshere" to that name.
This will display all the entries in the guestbook. The outside div is optional and customizable I think you get that part...
<div style="width:650px; height:425px; overflow:auto; border:1px solid #000000;">
<?php
$myFile = "questions.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
$notesout = str_replace("\r", "<br/>", $theData); echo $notesout;
?>
</div>
This is the part where the user will enter there information for the book... Replace nameofform with the name of the php file you make with the next block of code below this (if you want to log ip address or anything like that, that would be done here also.)
<form method="post" action="nameofform.php" style="border:#000000 2px solid; width:375px;">
<ul style="padding:0; margin:0; list-style-type:none; display:inline;">
<li style="display:inline;">Your Name:</li><input type="text" name="name" size="35" />
<br />
<li style="display:inline;">Your Email:</li></ul><input type="text" name="email" size="35" /><div style="padding-bottom:5px;"></div><br />
<textarea name="question" rows="4" cols="44">Questions about traveling, financial assistance, or why we do what we do ask them here...</textarea>
<br /><center>
<input type="submit" value="Send Your Question" style="text-align:center;" />
</center></form>
This checks the entry the user submits then writes it to the text file which is then displayed... Name this what you used above in the action field.
<?php
$visitor = $_POST['name'];
$visitormail = $_POST['email'];
$notes = $_POST['question'];
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>The e-mail address you entered was not correct.</h2>\n";
die ("<br />Your question has not been submitted. This page will bring you back<br />in 20 seconds or you may use your browsers back menu to resubmit.\n</div>
</div>
</body>
</html>");
}
if($notes == "Questions about traveling, financial assistance, or why we do what we do ask them here...")
{
echo "Please enter your Question. In the question field";
die ("<br />You may use your browsers back button or this page will bring you back in 20 seconds.</div>
</div>
</body>
</html>");
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<br />Please Fill in all of the information.\n";
die ("<br />You may use your browsers back button or this page will bring you back in 20 seconds.</div>
</div>
</body>
</html>");
}
$sendata="Email Address to respond to:". $visitormail;
$q="Comment from ". $visitor . " ". $notes . "Submitted:" . $todayis ;
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = "WHATEVERYOUWANTSUBJECTOFEMAILTOBE";
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
//OPTIONAL IF YOU WANT AN EMAIL EACH TIME A ENTRY IS POSTED mail("EMAILADDRESS@DOMAIN.COM", $subject, $sendata, $q);
$File = "nameofthetextfilegoeshere.txt";
$Handle = fopen($File, "r+");
$Data = '<p class="q">From:' . $visitor . '<br />Submitted on:' . $todayis . '<br />' . $notes . '</p><hr />' . "\n";
if ($Data <> "")
{
$existingText = file_get_contents($File);
fwrite($Handle, $Data . $existingText . "\n");
}
fclose($Handle);
?>
This doesn't have the admin side where you could edit posts and such if you want that its a little more but still uses that one text file and another form and another php section. If you want it with working terms as oppesed to the name such and such let me know .... If you want to add more or less things you can add them into the form and then in the second php part post['inputfieldsname'] defines the input to the variable on the other side of that equation then use that in the php. Make sense?
Nice bluewalrus. Here's a tip: When using double quotes there is no need for concatenation.
But otherwise looks pretty good.
bluewalrus
01-08-2009, 05:10 AM
You mean like this there's no need for?
'</p><hr />' . "\n"
When I tried it before with the \n inside it was displaying on the page as text.I found some other forum that said double quote it and keep it outside and that seemed to work. Once I get things working I tend to stop playing around with them until there's a needed change, hah (if there's a much more efficient way I'll give it a try).
JasonDFR
01-08-2009, 07:34 AM
"</p><hr />\n"
will work just like you want.
I don't mean to butt in, but I used to do the same thing Bluewalrus. I think it starts because a lot of the time you are doing things like:
<?php echo '<p class="class"><a href="/">text</a></p>' . "\n"; ?>
And in this case you would have to concatenate the \n because the single quotes are gonna print the literal \n if you don't. So depending on what you are echoing, sometimes you must concatenate, and sometimes you don't have to. It took me a while to get the hang of using single or double quotes, because like you, I like to find one way of doing something that works and stick to it.
Irishcash33
01-08-2009, 03:46 PM
Thanks so much Chris. I will try this tonight and see what happens!!!
$sendata="Email Address to respond to:". $visitormail;
$q="Comment from ". $visitor . " ". $notes . "Submitted:" . $todayis ;
I mean like that.. When your using double quotes - don't use conatenation... Unless there is a specific reason. Such as:
<?php
$var = "Hello";
$Hello = "GoodBye";
echo $$var;
?>
Irishcash33
01-09-2009, 02:42 PM
A few things Chris,
Does this just send the message to an email? or does it post to that page so anyone can see the message?
The 3 sections of code you laid out, should each of those be php files?
Also, how do I set permissions to the txt file, which is empty right?
Thanks dude
bluewalrus
01-09-2009, 08:14 PM
If your in your ftp right click, or apple click, or ctrl click, and then look for something like file attributes (in filezilla), properties, permissions maybe and click it then there should be a bunch of check boxes containing owner, group and public you can either check of all those or type in 777 in the text area at the bottom. It can email you when a new post has been set if you want it to that line is commented out in the code I gave you if you delete that comment it will email you. The 2 sections need to be php, the form one doesn't need to be but can be if you want, if you want to log ip addresses you'll need it to be php. Let me know what ftp you using if the finding the permissions above didn't help.
bluewalrus
01-09-2009, 08:15 PM
oo okay nile thanks.
Irishcash33
01-09-2009, 09:27 PM
ok Chris,
So I put the small bit of php code in the div tags in "guests.php", I put the form in the html file, and I put the large bit of php code in guest_book.php. The txt has all permissions set to it.
You can see the page here (http://www.headfirstgraphics.com/ourwedding/Chrisguestbook/chris_guest_book.html)
Here are the warnings I get! I was bound to get warnings on my first try!
Warning: fopen(guestbook.txt) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\Chrisguestbook\guest_book.php on line 52
Warning: fwrite(): supplied argument is not a valid stream resource in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\Chrisguestbook\guest_book.php on line 57
Warning: fclose(): supplied argument is not a valid stream resource in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\Chrisguestbook\guest_book.php on line 59
bluewalrus
01-09-2009, 09:31 PM
What are your permissions saying, 777? The other error's are from the text file not being able to open
Run this:
echo fileperms('guestbook.txt');
(and I'll do something to figure out the type), or run this:
echo substr(decoct(fileperms("thanks.php")),3);
Irishcash33
01-09-2009, 09:56 PM
right the first txt I had wasn't actually a txt file. So I uploaded a new txt file and right clicked. When I do I click on get info and I am able to see properties and permissions. Right now the permissions are 644, and when I go and change them to 777 and hit apply I get an error message.
My server is windows through godaddy and the ftp is transmit
Thanks
Will
Try:
chmod("guestbook.php", 777); // decimal; probably incorrect
Once you run this, run my 2nd code, and tell me the output.
Irishcash33
01-09-2009, 10:26 PM
Where do I run this? do I put this in guest_book.php?
Oh, sorry the code should be:
chmod("guestbook.txt", 777); // decimal; probably incorrect
And put it in the same file as guestbook.txt.
Once you upload the file - and Go to it. Then put this in(overwrite it):
echo substr(decoct(fileperms("thanks.php")),3);
And tell me/bluewalrus the output.
Irishcash33
01-09-2009, 10:34 PM
Ok I put the first line of code in the txt file. How do I overwrite it? This is what I see when I look at the properties.
http://www.headfirstgraphics.com/ourwedding/Chrisguestbook/txtinfo.png
bluewalrus
01-09-2009, 11:05 PM
What does the error message say and is it through godaddy, the ftp, or the site when accessing the txt file? If its though the ftp try going into godaddy and into your control panel and changing it there (not sure where there but somewhere hah).
bluewalrus
01-09-2009, 11:06 PM
oo check all the blocks or type in 777 at the bottom
Irishcash33
01-09-2009, 11:28 PM
yea I checked the boxes and thats when I get the error
Error -142: remote chmod failed
It's the ftp that pops up the error..
bluewalrus
01-09-2009, 11:33 PM
Try this http://help.godaddy.com/article/2323
Irishcash33
01-09-2009, 11:59 PM
Thanks Chris,
I don't think it's a godaddy thing. I looked into it. My server is a windows server.
I looked into the transmit(ftp) settings and took off the auto set permissions and the file still uploads as 644 and gets an error when I change to 777
bluewalrus
01-10-2009, 12:15 AM
there might be another work around using php to change the permissions i'll post that in a bit i'm going out right now check back around midnight or tomorrow
bluewalrus
01-10-2009, 05:38 AM
This is a sloppy work around but... put the text file in another directory by itself then link the directory addressed in this with that directory then load this page once and it should set it.
<?php
$dir = '/change me change me change me/';
$d = dir($dir);
while(FALSE !== ($entry = $d->read()))
{
if($entry != '.' && $entry != '..')
{
// get the file permissions
$perms = substr(sprintf('%o', fileperms($dir.$entry)), -4);
if($perms !== '0777')
{
if(chmod($dir.$entry, 0777)===TRUE)
{
//WORKED DID CHANGE
echo "Your textfile should be writeable now YAY!";
}
else
{
//ERROR DIDN'T CHANGE
echo "Chris messed up.";
}
}
}
}
?>
Make sure the directory you have guestbook.php also 777.
Irishcash33
01-11-2009, 09:00 PM
Ok So I made file permission.php with the code you gave me. I link the dir with txt/guestbook.txt
When I go to the permission.php file I get these errors
Warning: dir(txt/guestbook.txt) [function.dir]: failed to open dir: No error in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\Chrisguestbook\permission.php on line 6
Fatal error: Call to a member function read() on a non-object in D:\Hosting\3030954\html\HeadFirstGraphics\ourwedding\Chrisguestbook\permission.php on line 7
The directory has all permissions.
also i put this code that you gave me at the beginning in guests.php
<div style="width:650px; height:425px; overflow:auto; border:1px solid #000000;">
<?php
$myFile = "txt/guestbook.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
$notesout = str_replace("\r", "<br/>", $theData); echo $notesout;
?>
</div>
But it no file references guests.php...I assume some file is made to open this code...could this be a problem?
Thanks
Will
bluewalrus
01-11-2009, 09:06 PM
wanna send me your ftp info on facebook and I'll see if I can get it working i'm kinda confused with everything you just sent. or aim/ichat me I'm at zzzzwannnnn
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.