Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Guest Book - No Database

    I found this at hotscripts and it was about 10 files and a whole lotta includes and requires so I thoug I would bring it down to 3 files, 2 which you don't even see.

    create a file on you directory named data.php and save it with NO CODING inside it.

    create index.php and this code:

    PHP Code:
     <html>
      <head>
       <style> @import "stylesheet.css"; </style>
       <title> My Guest Book </title>
      </head>
      <body>

       <div class="thread">
        <?php include "data.php"?>
       </div>

       <div class="add">
       <b>Add entry</b> <br/> <br/>

       <form action="insert.php" method="post">
        <input type="hidden" name="posted" value="yes">
        Nickname: <input type="text" name="name"> <br/> <br/>
        Post:<br/>
        <textarea cols="50" rows="5" name="post">Enter Any Comment Here...</textarea> <br/>
        <input type="submit" value="Submit">
       </form> 
      </div>

      </body>
     </html>
    And that will have your form and display your comments and finally all you need is the 2nd page you won't see.

    insert.php
    PHP Code:
    <?php
    $allowed_html_tags 
    "";
    $addtotop "1"// This determines the order to display it. Leave for newest comments on top or change to 0 for oldest to newest.

    // Checks if the user wants to view the form or add a entry
    if (
    $_SERVER['REQUEST_METHOD'] == 'POST' ) {

                 
    // Make sure the script works if register_globals is off
                 
    $name $HTTP_POST_VARS['name'];
                 
    $post $HTTP_POST_VARS['post'];

                 
    // Process the Information Entered and Remove Stuff
                 
    $post strip_tags($post$allowed_html_tags); // Strip HTML
                 
    $post stripslashes($post); // Strip Slashes

                 
    $time date("F jS Y, h:iA");  

                 if (
    $addtotop == "0" ) {

                              
    // Writes the user's entry to a file
                              
    $fp fopen("data.php",  "a");  
                              
    fputs($fp"<p><b>Posted by:</b> " $name "</p><p>" $post "</p><p><b>Time: </b>" $time "</p>");
                              
    fclose($fp);

                 }

                 if (
    $addtotop == "1" ) {

                              
    // Get all the current entries and put it in a string
                              
    $att1 "data.php";
                              
    $att2 fopen ($att1"rb");
                              
    $currententries fread ($att2filesize ($att1));
                              
    fclose ($att2);

                              
    // Writes the user's post to a file
                              
    $fp fopen("data.php",  "w+");  
                              
    fputs($fp"<p><b>Posted by:</b> " $name "</p><p>" $post "</p><p><b>Time: </b>" $time "</p>" $currententries);
                              
    fclose($fp);

                 }

    header("Location: index.php?error=false");

    } else {
    header("Location: index.php?error=true");
    }
    ?>
    feel free to add to the script. I can't say otherwise.

  • #2
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    This is a great script. Is there anyone who could take the time and make it spamproof? So you had to include a word in the comment, that is not used by spammers? If the word is included in the comment, the comment will get posted and if not, it will be left out of course. And if the word is in the comment, it will get hidden...
    .
    .

  • #3
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Also, I get this error the first time I try to post:

    Warning: fread(): Length parameter must be greater than 0. in c:\programmer\easyphp1-8\www\insert.php on line 33

    Warning: Cannot modify header information - headers already sent by (output started at c:\programmer\easyphp1-8\www\insert.php:33) in c:\programmer\easyphp1-8\www\insert.php on line 43

    Then reload and suddenly there's two comments of the same.
    .
    .

  • #4
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    That's server problem, can't help you. I could make it spam proof, like a cookie for every 5 minutes you comment.

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    Often what I find is a in a comments page people will strip_tags on a variable then send it straight to the database. This means that if a guy puts a link (<a href="#">naughty angels</a> you will still have that entry stored in the database. Here is a small php snippet to stop that from happening.

    PHP Code:
    <?php 
    $message 
    "What ever you want it to be.";//From a form, whatever.
    $message1 strip_tags($message);
    if ((
    strlen($message)) > (strlen($message1))){
        
    $error true;
            echo(
    "No tags allowed, fool");
            exit;
        } else {
        
    //proceed with database addition, or whatever
        
    }
    ?>
    Last edited by idalatob; 09-05-2007 at 01:01 PM. Reason: Add php tags

  • #6
    New Coder
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol a guestbook only needs one file...

    Just seems beond basic to me since I am developing a forums :P

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    what? why? how?
    this thread was made in april what was the point in bringing it back to life?

  • #8
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    im using that at my site thanks so much

  • #9
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I noticed that at the bottom you made a reference to header index.php.

    I am wanting to add the guest book to all my article pages I want the comments and form and article all to be on one page. Is this possible? thanks

  • #10
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have a problem here. I wonder if anyone can solve it? When i run the script on localhost, saving all files as a php extension where data.php has no codings and the rest of the files has it into a directory called example.php (directory as in a folder and folder.php :O) When i type Nickname as ASD and posted ASD text, there isn't any content displayed other than the time and posted by seems empty too! As well, i opened the data.php file, not a folder. I used Dreamweaver to save it as a php file and it seems to be able to display nothing except the time, etc!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •