2019-02-24 Pujan Niroula 3 Minute(s) Read

Create Guestbook in PHP

img-thumbnails.png

Guestbook is not mandatory for site but if you want to have a guestbook where visitor of your site leaves message publicly then this post is for you. Guestbook is a better way to show your site's fame. If a guest appreciate your product on site through contact us form then just you will know but If a visitor publicly posted on guestbook then everyone will know your service or product's fame.

Guestbook Example

Most of guestbook script available on internet is based on PHP and Mysql. That is little lengthy process where you have to setup database and tables. But today I will show you how to create guestbook without MYSQL.  

<?php
$file_name = 'guestbook.txt';
if(!file_exists($file_name)) {
        file_put_contents($file_name, '');
    }
function check_input($input){
    if(empty(trim($input))) {
        die('Fill all fields properly');
    } else {
        return htmlspecialchars($input);
    }
}
function add_entry($username, $message, $file_name) {
    $get_content = file_get_contents($file_name);
    $time = date('Y-m-d h:i A',time());
    $content = '<div class="container border rounded p-3 bg-light"><b>'.$username.'</b><span class="text-muted"> ('.$time.')</span>'.'<p class="text-dark">'.$message."</p></div>\n".$get_content;
    file_put_contents($file_name, $content);
}
if(isset($_POST['username']) && isset($_POST['message'])){
    $username=check_input($_POST['username']);
    $message=check_input($_POST['message']);
    add_entry($username, $message, $file_name);
}
$final_content = file_get_contents($file_name);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Simple Guestbook System by Pujann</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body class="bg-info">
<div class="container text-center">
    <h1>Simple Guestbook System without Mysql in PHP</h1>
    <span class="bg-light p-2">
        <?php echo substr_count($final_content, 'container border rounded p-3');?> Message(s)
    </span>
    <button class="btn btn-success" data-toggle="modal" data-target="#addMessage">Add New Message</button>
    <div class="row mt-2">
        <div class="col-md-6 offset-md-3 col-sm-12">
            <?php
            echo $final_content;
            ?>
        </div>
    </div>
</div>
<div class="modal fade" id="addMessage" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Leave a Message</h3>
            </div>
            <div class="modal-body">
                <div class="container border rounded bg-light p-2">
                    <form action="" method="post" class="form">
                        <input type="text" class="form-control mb-1" name="username" placeholder="Full Name(eg. John Doe)" required="">
                        <textarea name="message" id="" cols="10" rows="5" class="form-control" placeholder="Leave your message...." required=""></textarea>
                        <input type="submit" class="btn btn-danger mt-1" value="Submit">
                    </form>                
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Note: It will create a new file named guestbook.txt on the folder it is uploaded to and store all the guestbook messages. If you deleted guestbook.txt all data will be lost.

Thanks for reading...

Tags:php, how to,
Comments (108) Add New Comment
Margaret2024-03-03 8:31 PM

An impressive share! I've just forwarded this onto a co-worker who was doing a little homework on this. And he in fact bought me dinner because I found it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanks for spending some time to talk about this matter here on your internet site.

Reply
Maira2024-03-03 6:41 PM

This is really interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your website in my social networks!

Reply
Stefanie2024-03-03 2:18 PM

If some one desires expert view on the topic of blogging and site-building after that i advise him/her to visit this website, Keep up the pleasant work.

Reply
Howard2024-03-03 9:55 AM

Keep this going please, great job!

Reply
Alton2024-03-03 4:00 AM

Hey there, You have done a great job. I will certainly digg it and personally recommend to my friends. I am confident they'll be benefited from this web site.

Reply
Nicholas2024-03-03 3:48 AM

When someone writes an post he/she retains the image of a user in his/her brain that how a user can be aware of it. Thus that's why this paragraph is amazing. Thanks!

Reply
Jasmine2024-03-03 3:06 AM

Quality articles is the crucial to attract the viewers to pay a visit the web site, that's what this website is providing.

Reply
Mireya2024-03-02 11:05 PM

Very nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed surfing around your blog posts. In any case I will be subscribing to your feed and I hope you write again very soon!

Reply
Winston2024-03-02 3:10 PM

What a information of un-ambiguity and preserveness of precious knowledge about unexpected feelings.

Reply
Marko2024-03-02 2:09 PM

Everyone loves what you guys are up too. This type of clever work and reporting! Keep up the excellent works guys I've added you guys to our blogroll.

Reply
Eddy2024-03-02 1:55 PM

Fantastic beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear idea

Reply
Phillipp2024-03-02 1:54 PM

Wonderful blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Thank you

Reply
Suzette2024-03-02 1:53 PM

If you desire to take a good deal from this paragraph then you have to apply such methods to your won webpage.

Reply
Denis2024-03-02 1:51 PM

I know this site gives quality depending articles or reviews and extra stuff, is there any other web page which gives such information in quality?

Reply
Ada2024-03-02 1:46 PM

I think what you said made a ton of sense. But, what about this? what if you wrote a catchier title? I ain't suggesting your content isn't solid., but suppose you added a headline to possibly get people's attention? I mean Create Guestbook in PHP is a little vanilla. You might look at Yahoo's front page and note how they create post headlines to get people interested. You might add a related video or a picture or two to get people interested about everything've written. Just my opinion, it could make your website a little livelier.

Reply
Tiara2024-03-02 1:46 PM

Wow, that's what I was looking for, what a data! existing here at this website, thanks admin of this site.

Reply
Abe2024-03-02 1:38 PM

This site really has all the information I wanted concerning this subject and didn't know who to ask.

Reply
Rickey2024-03-02 1:28 PM

Currently it seems like Expression Engine is the top blogging platform available right now. (from what I've read) Is that what you're using on your blog?

Reply
Kara2024-03-02 1:12 PM

I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I'm looking to design my own blog and would like to find out where u got this from. thank you

Reply
Monika2024-03-02 8:21 AM

Wow, incredible weblog format! How lengthy have you been blogging for? you made blogging look easy. The whole look of your site is great, as neatly as the content!

Reply
Kelsey2024-03-02 4:24 AM

It's not my first time to visit this web site, i am visiting this site dailly and take pleasant facts from here every day.

Reply
Reggie2024-03-02 4:08 AM

I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get bought an impatience over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike.

Reply
Nannie2024-03-01 11:51 PM

always i used to read smaller content that also clear their motive, and that is also happening with this piece of writing which I am reading here.

Reply
Doretha2024-03-01 8:43 PM

Please let me know if you're looking for a writer for your weblog. You have some really great articles and I feel I would be a good asset. If you ever want to take some of the load off, I'd really like to write some articles for your blog in exchange for a link back to mine. Please blast me an email if interested. Many thanks!

Reply
Sherri2024-03-01 6:00 PM

Wonderful beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

Reply
Cindi2024-03-01 7:14 AM

Very energetic article, I enjoyed that a lot. Will there be a part 2?

Reply
Shawnee2024-03-01 6:42 AM

I used to be able to find good info from your articles.

Reply
Adriene2024-03-01 6:41 AM

It's a shame you don't have a donate button! I'd certainly donate to this superb blog! I suppose for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this blog with my Facebook group. Talk soon!

Reply
Anja2024-03-01 6:41 AM

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us something informative to read?

Reply
Caryn2024-03-01 6:40 AM

Hi there Dear, are you actually visiting this web page on a regular basis, if so after that you will definitely take fastidious knowledge.

Reply
Shawn2024-03-01 6:40 AM

Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's tough to get that "perfect balance" between usability and appearance. I must say you've done a amazing job with this. In addition, the blog loads very fast for me on Internet explorer. Superb Blog!

Reply
Myrna2024-03-01 6:40 AM

I am curious to find out what blog system you're working with? I'm having some minor security problems with my latest website and I'd like to find something more risk-free. Do you have any solutions?

Reply
Genie2024-03-01 6:31 AM

Because the admin of this web page is working, no question very quickly it will be well-known, due to its feature contents.

Reply
Rene2024-03-01 6:28 AM

Post writing is also a fun, if you know after that you can write if not it is difficult to write.

Reply
Janette2024-03-01 6:28 AM

This design is spectacular! You obviously know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Fantastic job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

Reply
Sophie2024-03-01 6:28 AM

Great article. I will be dealing with many of these issues as well..

Reply
Jessika2024-03-01 6:27 AM

An outstanding share! I have just forwarded this onto a co-worker who was conducting a little homework on this. And he actually bought me breakfast because I found it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks for spending some time to talk about this issue here on your website.

Reply
Lilliana2024-03-01 4:43 AM

It's really a great and useful piece of information. I'm happy that you simply shared this useful information with us. Please stay us up to date like this. Thanks for sharing.

Reply
Lashawnda2024-03-01 2:46 AM

My spouse and I absolutely love your blog and find almost all of your post's to be what precisely I'm looking for. Do you offer guest writers to write content to suit your needs? I wouldn't mind composing a post or elaborating on many of the subjects you write related to here. Again, awesome weblog!

Reply
Valencia2024-02-28 12:01 PM

After I originally commented I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve four emails with the same comment. There has to be a way you can remove me from that service? Cheers!

Reply
Oren2024-02-28 11:32 AM

Definitely believe that which you said. Your favorite reason appeared to be on the net the simplest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they just do not know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks

Reply
Regan2024-02-28 10:54 AM

Hi there! I know this is kinda off topic but I was wondering which blog platform are you using for this site? I'm getting fed up of Wordpress because I've had problems with hackers and I'm looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.

Reply
Valencia2024-02-28 7:46 AM

I like the valuable information you provide in your articles. I'll bookmark your blog and check again here regularly. I am quite certain I'll learn many new stuff right here! Best of luck for the next!

Reply
Rosalina2024-02-28 4:42 AM

What's up, I log on to your blog like every week. Your writing style is witty, keep up the good work!

Reply
Denisha2024-02-28 1:54 AM

Hello to all, how is all, I think every one is getting more from this site, and your views are good in support of new visitors.

Reply
Bradley2024-02-28 12:33 AM

Link exchange is nothing else except it is just placing the other person's blog link on your page at appropriate place and other person will also do similar in favor of you.

Reply
Jai2024-02-27 10:16 PM

This is very interesting, You're a very skilled blogger. I've joined your feed and look forward to seeking more of your great post. Also, I have shared your web site in my social networks!

Reply
Chase2024-02-27 9:04 PM

May I simply just say what a comfort to uncover an individual who really understands what they're talking about on the net. You actually know how to bring a problem to light and make it important. More people should check this out and understand this side of your story. I was surprised that you're not more popular because you surely have the gift.

Reply
Leonor2024-02-27 8:21 PM

Howdy! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I'm getting tired of Wordpress because I've had issues with hackers and I'm looking at alternatives for another platform. I would be fantastic if you could point me in the direction of a good platform.

Reply
Leila2024-02-27 7:17 PM

Hello, everything is going fine here and ofcourse every one is sharing information, that's truly good, keep up writing.

Reply
Sara2024-02-27 5:03 PM

Hello all, here every person is sharing these kinds of experience, so it's pleasant to read this web site, and I used to visit this webpage daily.

Reply
Earl2024-02-27 4:07 PM

Fantastic items from you, man. I have take into accout your stuff prior to and you're simply too great. I actually like what you've bought here, really like what you are stating and the best way by which you assert it. You're making it entertaining and you continue to take care of to stay it smart. I can't wait to learn far more from you. This is actually a wonderful web site.

Reply
Dominick2024-02-27 2:04 PM

If some one desires expert view concerning blogging afterward i suggest him/her to go to see this website, Keep up the pleasant work.

Reply
Nannette2024-02-26 2:11 PM

I always spent my half an hour to read this blog's posts every day along with a cup of coffee.

Reply
Asa2024-02-26 1:55 PM

Great post however I was wanting to know if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit more. Kudos!

Reply
Cheryle2024-02-26 9:24 AM

Hello there, just became aware of your blog through Google, and found that it's really informative. I am going to watch out for brussels. I'll appreciate if you continue this in future. Numerous people will be benefited from your writing. Cheers!

Reply
Julian2024-02-25 4:13 PM

This excellent website definitely has all the info I needed concerning this subject and didn't know who to ask.

Reply
Christa2024-02-25 9:44 AM

Hi would you mind letting me know which webhost you're using? I've loaded your blog in 3 completely different web browsers and I must say this blog loads a lot quicker then most. Can you recommend a good web hosting provider at a honest price? Thanks a lot, I appreciate it!

Reply
Jonathan2024-02-25 5:44 AM

I enjoy what you guys are up too. This sort of clever work and reporting! Keep up the terrific works guys I've included you guys to my own blogroll.

Reply
Genevieve2024-02-24 10:29 PM

I'm really inspired with your writing skills and also with the structure in your weblog. Is that this a paid subject or did you modify it yourself? Anyway keep up the nice quality writing, it's rare to see a nice weblog like this one these days..

Reply
Dian2024-02-24 10:25 PM

Hurrah! In the end I got a webpage from where I know how to genuinely obtain useful facts concerning my study and knowledge.

Reply
Isabel2024-02-24 9:13 PM

Great beat ! I would like to apprentice while you amend your website, how could i subscribe for a blog site? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

Reply
Tammy2024-02-24 8:35 PM

Hey would you mind letting me know which web host you're using? I've loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most. Can you recommend a good internet hosting provider at a reasonable price? Many thanks, I appreciate it!

Reply
Reta2024-02-24 8:18 PM

Heya i'm for the first time here. I came across this board and I find It really useful & it helped me out a lot. I hope to give something back and aid others like you aided me.

Reply
Mervin2024-02-24 8:18 PM

I was more than happy to find this web site. I want to to thank you for ones time just for this fantastic read!! I definitely liked every part of it and I have you saved to fav to check out new things on your web site.

Reply
Traci2024-02-24 8:17 PM

This is very attention-grabbing, You're an excessively professional blogger. I have joined your rss feed and sit up for searching for more of your magnificent post. Additionally, I have shared your site in my social networks

Reply
Concepcion2024-02-24 8:16 PM

An outstanding share! I have just forwarded this onto a colleague who has been conducting a little research on this. And he in fact bought me dinner due to the fact that I discovered it for him... lol. So allow me to reword this.... Thank YOU for the meal!! But yeah, thanks for spending time to discuss this topic here on your website.

Reply
Leandra2024-02-24 8:01 PM

Great goods from you, man. I've understand your stuff previous to and you are just extremely fantastic. I really like what you have acquired here, certainly like what you're saying and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can not wait to read far more from you. This is really a great site.

Reply
Evie2024-02-24 3:46 PM

I used to be able to find good advice from your blog posts.

Reply
Stacey2024-02-24 3:44 PM

Excellent article. I will be going through a few of these issues as well..

Reply
Etsuko2024-02-24 3:43 PM

I needed to thank you for this wonderful read!! I absolutely enjoyed every little bit of it. I have you bookmarked to check out new things you post…

Reply
Ethel2024-02-24 3:43 PM

What's Happening i am new to this, I stumbled upon this I've discovered It absolutely useful and it has aided me out loads. I hope to give a contribution & help other customers like its helped me. Good job.

Reply
Rodolfo2024-02-24 3:42 PM

you are really a good webmaster. The website loading pace is amazing. It seems that you are doing any unique trick. Moreover, The contents are masterwork. you've done a magnificent task in this matter!

Reply
Jasper2024-02-24 11:05 AM

Hi, I do believe this is an excellent blog. I stumbledupon it ;) I'm going to return yet again since i have bookmarked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

Reply
Dominga2024-02-23 10:41 PM

Somebody necessarily help to make critically articles I might state. That is the first time I frequented your web page and to this point? I surprised with the analysis you made to create this actual post amazing. Great job!

Reply
Aja2024-02-23 1:21 AM

fantastic publish, very informative. I ponder why the other experts of this sector don't notice this. You should continue your writing. I am sure, you have a great readers' base already!

Reply
Candida2024-02-16 12:21 AM

Hello, I do believe your site could possibly be having web browser compatibility problems. When I look at your website in Safari, it looks fine however, when opening in IE, it's got some overlapping issues. I merely wanted to provide you with a quick heads up! Besides that, wonderful site!

Reply
Hildegarde2024-02-13 9:49 AM

Hello, I enjoy reading all of your article. I wanted to write a little comment to support you.

Reply
Orval2024-02-13 2:16 AM

Hello my loved one! I want to say that this post is amazing, nice written and include approximately all important infos. I would like to see more posts like this .

Reply
Sabrina2024-02-11 2:53 PM

Hey there! Would you mind if I share your blog with my twitter group? There's a lot of folks that I think would really enjoy your content. Please let me know. Cheers

Reply
Rogelio2024-02-11 7:41 AM

Currently it seems like Wordpress is the best blogging platform out there right now. (from what I've read) Is that what you're using on your blog?

Reply
Alma2024-02-10 10:38 AM

When some one searches for his vital thing, so he/she wishes to be available that in detail, therefore that thing is maintained over here.

Reply
Luther2024-02-09 6:57 AM

For latest news you have to go to see the web and on web I found this website as a finest site for most recent updates.

Reply
Tammara2024-02-09 12:37 AM

Greetings! I've been following your website for a long time now and finally got the bravery to go ahead and give you a shout out from Humble Texas! Just wanted to mention keep up the great work!

Reply
avon Representative Uk2021-06-07 6:56 PM

Hi there, for all time i used to check website posts here early in the dawn, because i like to find out more and more.

Reply
Mehmet2022-03-26 12:51 PM

w

buy avon online uk2021-05-26 2:42 PM

Great blog here! Also your web site loads up very fast! What web host are you using? Can I get your affiliate link to your host? I wish my website loaded up as fast as yours lol

Reply
9kg condenser tumble dryer2021-05-21 4:25 AM

Hi there are using Wordpress for your blog platform? I'm new to the blog world but I'm trying to get started and set up my own. Do you need any coding knowledge to make your own blog? Any help would be greatly appreciated!

Reply
Kickass Torrents2020-02-08 11:25 AM

Nice post. I learn something new and challenging on sites I stumbleupon everyday. It will always be helpful to read through articles from other authors and practice something from other sites.

Reply

What's up, after reading this awesome post i am too glad to share my knowledge here with mates.

Reply
Jav HD2019-09-30 3:39 AM

My programmer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using WordPress on a number of websites for about a year and am anxious about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be greatly appreciated!

Reply