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 (34) Add New Comment
Jonathan2024-09-17 8:27 AM

WOW just what I was searching for. Came here by searching for Guestbook system

Reply
Saffet Erdogan2024-09-15 3:29 PM

Hello , I hope this message finds you well. I am reaching out to you for my money investment . I am currently facing issues with President Recep Tayyip Erdogan, President Recep has confiscated my money in Turkey. I got a tip off that President Recep Tayyip Erdogan is trying to trace my money abroad. In light of this situation, I am seeking to transfer as an Investor €45,000,000 Million euros in my Account in Germany to your bank account and you will receive the funds in your Bank Account as an Investment Manager , you can invest money in any Lucrative business of your choice, By Transferring the money to you , I will effectively protect these money From.the Government of President Recep Tayyip Erdogan. I kindly ask for your prompt response to confirm your willingness to invest the money. Once I receive your confirmation, I will provide you with further details . Please reply to me directly with this email. : esaffet81@gmail.com Thank you . Warm regards, Mr. Saffet Erdogan

Reply
JamesNub2024-09-13 9:13 AM

?c??????a ???????x ?o?????? ????? ?????o???? P???T?EM ?O BCE? ???????? ???????????. ???????c??e ???e????.?????e ?a????a??. ?E? ????XA. ??e?? ??????????a ?a??????? ?ec?????? ???????? ??????? ????????

Reply
BrianHough2024-09-12 11:24 PM

Los sitios web no registrados de comercio de opciones binarias pueden atrapar inversores inteligentes opciones binarias prohibidas

Reply
MichaelStymn2024-09-12 2:38 PM

??????? ????????????? ???????? ??????????? ??? ???????? ????????? ? ?????. ?? ?????????? ???????? ??????? ??? ???????????? ???????????????????? ? ???????????? ????????. ??????? ???????? ????????????? ? ?????????????? ?????? — ???????? ???????? ????? ?????? ????????? ??? ????

Reply
Harvey2024-09-12 9:56 AM

I loved as much as you'll receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this hike.

Reply
Jameseneft2024-09-12 2:59 AM

???????? ?????? ???????????? ????? ????? Tether TRC20 USDT ?? ???????? UAH ?? ??????????????? ?????? ????? ??????????? ??????

Reply
Andreas2024-09-12 2:24 AM

Hello, everything is going perfectly here and ofcourse every one is sharing information, that's genuinely excellent, keep up writing.

Reply
DanielJut2024-09-11 12:31 PM

Mega Darknet - ??? secret portal ??? anonymity ? security always come first. ???????? Mega Darknet is associated ? a multitude of ???????????? ? intrigue. ??? not just a web platform; ??? ?????? ? secret internet ??? ??????????? ????? ?????? ????????. ????? ?? will discover unique resources ? special offers ??????? expand your horizons. mega fo ??????

Reply
Franksathy2024-09-09 3:31 AM

? ????? Kraken ???? ???????????? ? ?????????????????? are a priority. ??? ???????? ????????? ??????????? convenient access ? multiple resources ??????? ??????????? complete secrecy. ????? rules of regular internet ?? ????????? ??? ???? ??? ??????????? ???????? ???????????? network resources. kraken darknet ??????

Reply
Cherie Puente2024-09-08 6:30 AM

To the pujann.com.np owner, Thanks for the well-researched and well-written post!

Reply
RandyKem2024-09-07 1:29 AM

????????????? ??????????? ???????. ?????? ??????? ??????? ????? ????? ???????? ?? ????????????? ????? ? ??????????? ?? ???????? ??????????? ??????? ?? ?????

Reply
Emely Sconce2024-09-06 10:41 PM

To the pujann.com.np administrator, Your posts are always well researched.

Reply
WilliamLib2024-09-06 8:25 PM

?????? ??? ??????????? ?? ?????????????. ??????? ????? ??????? ? ???????? ????????-???????? ? ????????? ?? ?????? ?? ????????? ????. ?????? ???? ????????? ??????????? ??????? ?????? ? ??????

Reply
Brandonpoord2024-09-06 5:35 PM

? ???????????? ??????????? ???????????? ?????? ? ??????? ???? ????? – ? ??????-???????? ? ?????? ???????? ????????? ????? ?????????? 40 40

Reply
GregoryRox2024-09-06 9:27 AM

?????? 7 ??? — ??? ???????. ????????????? ?????? ????????????? ???????? ?????????? ????? ? ???????? ?? ???????. ????? ????? ??????????? ?????????? ????????? ?????? ???????? ??????? ????????? ?????? ?????????? ????? ?????????? ? ????????? ?????? ???????????. ?????? ?? ???????????

Reply
PedroGrige2024-09-06 5:31 AM

???? ?? ??????????? ?????. ?????? ???? ? ???????. ???????????? ?????????. ????????? · ????????? ?????????. ????????? ????. ??????????? ????????. ???????? ???????? ???????? ?????????

Reply
Phillipflook2024-09-06 3:51 AM

?????? ????? ? ????? ??????? ? ?????? – ?????? ??????????? ? ???? ???????? ? ???????????? ??????? ?????? ???? ????? ???????

Reply
Byron2024-09-05 12:34 PM

I was recommended this blog by my cousin. I'm now not certain whether or not this publish is written by way of him as no one else realize such distinct approximately my difficulty. You're amazing! Thank you!

Reply
LeonardAcark2024-09-05 7:05 AM

?????????????? ?????????? ???????? ???????? ???????????? ? ?????????? ???????????. ? 2019 ???? ?? ????? ??????????? ???????????? ???????? ??????? ????????? ????????? ????? ?????????? ?? ?????? ??????????. ???? ???? ?????????? ?????????? ?????? ? ?????? ??????? ??????? ? ?????????? ??????????? ? ????????????????? ??????????? ????????? ????? ??? ??????? ? ?????

Reply
Everette2024-09-04 1:25 PM

High quality, beautiful cam site with a great design.

Reply
Karri2024-09-04 12:56 PM

Just wish to say your article is as amazing. The clarity in your post is just excellent and i could assume you are an expert on this subject. Fine with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.

Reply
Leonardo2024-05-01 4:35 AM

Hello! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no back up. Do you have any methods to protect against hackers?

Reply
Janina2024-04-30 5:57 PM

Very nice article, exactly what I wanted to find.

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