BleepingComputer.com: PHP Guestbook Problem

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

PHP Guestbook Problem Hopefully an easy fix!

#1 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

Posted 31 October 2009 - 04:52 PM

Ok, I admit it, this is basically a follow-up of my "HTML Guestbook Will Not Work" ( http://www.bleepingcomputer.com/forums/topic267704.html ) topic, but since I switched to PHP I figured I should create a new topic.

Anyway, I've been having some trouble getting the guestbook on my website ( http://www.fett1138.net ) to work properly. At first I used html, and got nowhere, then flash, also didn't work out for me, so now I'm trying to use php. I got some code for a guestbook that writes to a txt file at [ http://www.webmasterworld.com/forum88/1104.htm ] because I don't really want to use MySQL. Some people have made that code work, NOT ME.

I edited the code for my own use, which can be seen below...
<h5>Please type your comment and screen name below and press 'Submit' to add it.</h5>
<form method="post" action="">
Name: <br />
<input type="text" name="name" size="30">
<br>
E-mail: <br />
<input type="text" name="email" size="30">
<br>
Website: <br />
<input type="text" name="homepage" size="30" value="http://">
<br>
Comment: <br />
<textarea name="message" wrap="VIRTUAL" cols="50" rows="5"></textarea>
<br>
<input type="hidden" name="from" value="<? echo $HTTP_REFERER ?>">
<input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset value="Reset>
</form>
		<div class="credits">
------------------------------------------------------------------------------------------------
		</div>
		<h3>Comments</h3>
<!-- start php code -->

<?
if ($message)
{
$name = strip_tags($name);
$email = strip_tags($email);
$homepage = strip_tags($homepage);
$message = strip_tags($message);
$message = ereg_replace("\r\n\r\n", "\n<P>", $message);

if (get_magic_quotes_gpc())
{
$message = stripslashes($message);
$name = stripslashes($name);
}

$date = date("l, F j Y");
$message = "<B>$name </B> -- $date -- <a href=mailto:$email>$email</a><br>$message<br><a href=$homepageurl>$homepagename</a><br>Refered by $from<br><br>\r\n";

$textfile = "guestbook.txt";
if ($fp = @fopen ($textfile, "r"))
{
$oldmessages = @fread($fp,filesize($textfile));
@fclose(fp);
}

$fp = fopen ($textfile, "w");
fwrite ($fp, $message);
fwrite ($fp, $oldmessages);
fclose ($fp);
}

@readfile("guestbook.txt");
?>

<!-- end php code --> 


I have uploaded "guestbook.txt" and set CHMOD on both "guestbook.php" and "guestbook.txt" to 777.

If anyone who has more php experience than me could tell me what the problem is, it would be greatly appreciated! :thumbsup:

Thanks

#2 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 02 November 2009 - 07:24 PM

Have you got the files in the same directory? And does your server support PHP?
If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#3 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

Posted 03 November 2009 - 05:39 PM

I honestly can't imagine that they don't support PHP, but I'll try to call them when I get the free time, and yes they're all on the same directory. I honestly don't understand why these things seem to refuse to work for me when they obviously work for other people.

Also, a very simple question for someone who knows PHP, how can I make the "Website" field optional?

UPDATE: I contacted GoDaddy by email and asked if they did not support PHP, and what they think the problem is.

This post has been edited by Fett 1138: 03 November 2009 - 10:00 PM


#4 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 04 November 2009 - 09:39 AM

Godaddy supports both PHP and ASP.
Godaddy is a huge web hosting service provider, you should expect them to support all the popular stuff.

http://www.godaddy.com/hosting/web-hosting.aspx#details

#5 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

Posted 04 November 2009 - 09:12 PM

Ok, I contacted GoDaddy, and they assured me that they support PHP, but didn't tell me what the issue might be. I honestly don't understand why it's taking so long to figure out something that should be moderately simple.

And again, how might I make the website field optional?

#6 User is online   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 04 November 2009 - 09:34 PM

Quote

And again, how might I make the website field optional?


By definition, all fields are optional. If a developer requires that a field be mandatory, then before the data is submitted, javascript is used to make sure that the field has been populated.

Quote

I contacted GoDaddy, and they assured me that they support PHP, but didn't tell me what the issue might be

It is not their job to figure out what is wrong with your code.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#7 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 04 November 2009 - 11:37 PM

You should install WAMP and test your code locally before you upload to server. BY default WAMP shows all errors in PHP so you can find out what problem you are having.

http://www.wampserver.com/en/

#8 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

Posted 05 November 2009 - 10:59 PM

I installed WampServer 2 and have it running but I honestly have no idea how to test the code, I looked through the WAMP website and couldn't find anything helpful.

#9 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 06 November 2009 - 12:48 AM

Assuming you installed WAMP in c:\wamp

C:\wamp\www becomes your web site folder, similar to folder you would upload files to at godaddy. Treat it in similar manner.
Copy your code files to c:\wamp\www.
Make sure wampserver is running (in system tray a speedometer like icon). If not run it from Start Menu > WampServer > start wampserver. In Vista and 7 you would need to give permission to run as server. If the icon is red in color, click on it and select start all services.
Open browser and type 127.0.0.1 in the address field to check your local website.
If your code file was c:\wamp\www\guestbook.php type in browser http://127.0.0.1/guestbook.php

Using WAMP in this way makes it easier and faster to test and fix web sites at your own computer before you upload the files and make them public.

By default WAMP has configured php.ini to show all errors (which you wont see on an online web server because most servers have them disabled by default). So if your PHP code is not working, you will see which line in your php code is causing what error right in your browser. You can debug and fix your code using that information.

This post has been edited by Romeo29: 06 November 2009 - 12:53 AM


#10 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 06 November 2009 - 06:14 AM

Try this. It is one i made earlier on this year, feel free to use/modify it but please leave the link at the bottom of the form and the information at the start...

A download is avaliable here.

It writes to a .dat file and also checks for blank fields, future updates will have spam prevtion included, but need to find some free time...

Good luck

~Kam
If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#11 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 06 November 2009 - 09:00 AM

found some free time and added the spam :thumbsup:

(for some reason i can't edit my post above?? any idea's?)

~Kam
If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#12 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

Posted 06 November 2009 - 01:45 PM

I used KamakaZ's code and uploaded the file to my website, I made some (seemingly) harmless cosmetic changes (removed the "My Guestbook" title, moved "* Marks a required field" up in the page, and changed "Previous Entries:" to "Comments:".) Whenever I look at the page the whole "<!--------------------------------------------------------------------------------- Author: Bradly Sharpe Copyright © 2009 ..." is visible along with...


"Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/content/f/e/t/fett1138/html/guestb.php on line 103

Warning: include(http://202.45.110.174/code/include.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/content/f/e/t/fett1138/html/guestb.php on line 103

Warning: include() [function.include]: Failed opening 'http://202.45.110.174/code/include.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/f/e/t/fett1138/html/guestb.php on line 103"


Other than that, comments CAN BE POSTED, so all I want to do is remove the warnings and make the first part (the <!--- part) not viewable on the page

The page can be viewed at http://www.fett1138.net/guestb.php

Anyone know what the problem could be?

UPDATE: I Fixed the warnings by replacing "<? include('http://202.45.110.174/code/include.php')?>" with the actual code from [ http://202.45.110.174/code/include.php ], but the other part (the <!--- part) is still there.

EDIT:
It seems to me that the only way to fix the "<!--- part" is to remove it, but then I'm no PHP expert.

This post has been edited by Fett 1138: 06 November 2009 - 06:15 PM


#13 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 06 November 2009 - 08:19 PM

<!-- stuff --> is a HTML comment, i'm guessing you've placed it between <?php ?> tags, so replace the <!-- with /* and the --> with */ which should get rid of your problem.

Does the spam filter work for you? Try add a comment with xxx in the message/comment field, you should get an error message then redirected.


Hope all goes well,

~Kam

(I do have to agree with groovicus, that if you did spend a couple of hours LEARNING php, then you could have created something similar within 2-3 hours.)

EDIT: If spam filtering doesn't work, a pm if you want to resolve it, otherwise i'm glad to see your issue is finally sorted :thumbsup:

This post has been edited by KamakaZ: 06 November 2009 - 08:22 PM

If I am helping you and don't reply in 24 hours please send me a PM

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.

#14 User is offline   Fett 1138 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 32
  • Joined: 12-February 09
  • Gender:Male
  • Location:Texas

  Posted 06 November 2009 - 09:00 PM

Thank you, I'm trembling out of excitement right now, I've been working on that thing for several weeks now and only once before this got it to post a comment that disappeared after the first refresh! I apologize for all the trouble that I've put you, and every one else who's helped me on this through. Thank for that code, it's the only thing that worked!

Again, I can't thank you enough!,
Fett1138 :thumbsup:

#15 User is online   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 06 November 2009 - 09:31 PM

Quote

Thank you, I'm trembling out of excitement right now, I've been working on that thing for several weeks now


Welcome to the world of development. I have often spent days and weeks trying to accomplish some task, and when I di, I want to rip off my clothes and run up and down the hallways screaming. :thumbsup: It's not a pretty picture, I know.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users