Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP Guestbook Problem


  • Please log in to reply
15 replies to this topic

#1 Fett 1138

Fett 1138

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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/t/267704/html-guestbook-will-not-work/ ) 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...


Name _linenums:0'><h5>Please type your comment and screen name below and press 'Submit' to add it.</h5><form method="post" action="">Name: <input type="text" name="name" size="30">E-mail: <input type="text" name="email" size="30">Website: <input type="text" name="homepage" size="30" value="http://">Comment: <textarea name="message" wrap="VIRTUAL" cols="50" rows="5"></textarea><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>$message<a href=$homepageurl>$homepagename</a>Refered by $from\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

BC AdBot (Login to Remove)

 


#2 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:24 PM

Posted 02 November 2009 - 07:24 PM

Have you got the files in the same directory? And does your server support PHP?

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 Fett 1138

Fett 1138
  • Topic Starter

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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.

Edited by Fett 1138, 03 November 2009 - 10:00 PM.


#4 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:24 AM

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 Fett 1138

Fett 1138
  • Topic Starter

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:24 AM

Posted 04 November 2009 - 09:34 PM

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.

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.

#7 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:24 AM

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 Fett 1138

Fett 1138
  • Topic Starter

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:24 AM

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.

Edited by Romeo29, 06 November 2009 - 12:53 AM.


#10 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:24 PM

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

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 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:24 PM

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

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 Fett 1138

Fett 1138
  • Topic Starter

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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.

Edited by Fett 1138, 06 November 2009 - 06:15 PM.


#13 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:24 PM

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:

Edited by KamakaZ, 06 November 2009 - 08:22 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 Fett 1138

Fett 1138
  • Topic Starter

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Texas
  • Local time:07:24 AM

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 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:24 AM

Posted 06 November 2009 - 09:31 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users