Update date for PHP Post

This commit is contained in:
Evan G. 2024-04-27 13:45:59 -05:00
parent c23e9ce05b
commit 15cf8e3ad8
1 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
---
title: "PHP Guestbook"
date: 2024-04-20T14:24:47-05:00
date: 2024-04-27T14:24:47-05:00
tags:
- PHP
- learning
@ -14,28 +14,28 @@ PHP is a server-side scripting language. It can be used for a ton of things. The
# A guestbook
There was a lot of places I went to figure out PHP, mainly from [w3schools](https://w3schools.com) (**JS WARNING + AD WARNING**), the [PHP Documentation](https://www.php.net/manual/), and [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/). My plan from the beginning was using PHP to store data from a HTML Form, to a JSON File. This implementation could be later extended to use SQL, or other mediums. This is the first part of a guestbook. If you want to see my code, you should be able to see it here [code](https://git.fbievan.live/fbievan/Website-Redesign/src/branch/main/guestbook).
This has been implemented elsewhere, but I wanted the codebase to be very easy to maintain, so I created my own. This led to me having a better understanding of PHP. I have always kind of felt that I have always taken, without giving anything back, so I started work on this project, and hope that this can be a learning tool for some people.
A guestbook made in PHP has existed elsewhere, but I wanted the codebase to be very easy to maintain, so I created my own. This led to me having a better understanding of PHP. I have always kind of felt that I have always taken, without giving anything back, so I started work on this project, and hope that this can be a learning tool for some people.
This [blost](https://alpha.polymaths.social/@amin/statuses/01HW9D7JDTZK4HH6SCB4JAS2DW) is meant to be most of a preliminary to a further article about the complete redesign of this site, however I figure that a PHP development article would be pretty cool, so here it is.
## What this actually needed to do and the Original Structure of the Code
First, I needed to receive a request, this was done with an HTML form with a POST request. This POST was to a php script, which needed to first cleanse the HTML code of any scripting or styling, this i used htmlspecialchars function inside of PHP. I stored all of these in variables.
First, I needed to receive a request, this was done with an HTML form with a POST request. This POST was to a PHP script, which needed to first cleanse the HTML code of any scripting or styling, this I used htmlspecialchars function inside of PHP. I stored all of these in variables.
Secondly, I needed an array of these variables, so i setup an $savemsg array, which stored the name and message of that request in one array. After this, I used some IF statements to not exit from situations where the name or message was invalid. After those checks, the code also has already stored the existing data from the JSON file.
Secondly, I needed an array of these variables, so I set up a $savemsg array, which stored the name and message of that request in one array. After this, I used some IF statements to not exit from situations where the name or message was invalid. After those checks, the code also has already stored the existing data from the JSON file.
I then used an "array_unshift" to change the array that was gathered from the JSON file, and then with a file_put_contents then rewrote over the existing JSON file
## A redesign
Well, I didn't like the structure. At a meeting at my schools coding club (hey guys if you see this). I heard about classes and those structures, and I thought, I can use that in my own code. So when I got home, I redesigned the code to use a class. This meant that my code was now treating the variables as a variable inside of an object. This allowed for much easier expansion of what I wanted to add on later. While at it I also added dates, while there is no way to get the timezone of a user (without some major hacks that I did not want to do), without JavaScript. Which was the whole reason I created this project. So I settled for simply storing the date.
Well, I didn't like the structure. At a meeting at my schools coding club (hey guys if you see this). I heard about classes and those structures, and I thought, I can use that in my own code. So when I got home, I redesigned the code to use a class. This meant that my code was now treating the variables as a variable inside an object. This allowed for much easier expansion of what I wanted to add on later. While at it, I also added dates, while there is no way to get the timezone of a user (without some major hacks that I did not want to do), without JavaScript. The whole reason I started this project, is that I wanted to do it without JavaScript.
## RSS Feed
This is a very similar structure to what I used in HTML with PHP, to do this, I simply used a foreach loop which cycled through every object in the JSON array and make an item with the title of the item's user, and then the description being the message. It was fairly simple, but took a little bit extra to work out the kinks with.
This is a very similar structure to what I used in HTML with PHP, to do this. I simply used a foreach loop which cycled through every object in the JSON array and make an item with the title of the item's user, and then the description being the message. It was fairly simple, but took a bit extra to work out the kinks with.
## Concluding thoughts
I found this endeavour to be very beneficial in terms of having something to code. The obvious next step would be to do the same thing with SQL. I believe this project is something I would recommend others doing. This is something that taught me a lot about the way that programming works. It had me thinking of solutions to these problems, and had me challenge myself in many different ways. I truly feel like I learned a ton through this process. There are no words that describe how much time I spent working on this project, and how much I appreciated anyone following me on the Fediverse. Shoutouts to
I found this endeavor to be very beneficial in terms of having something to code. The obvious next step would be to do the same thing with SQL. I believe this project is something I would recommend others doing. This is something that taught me a lot about the way that programming works. It had me thinking of solutions to these problems, and had me challenge myself in many ways. I truly feel like I learned a ton through this process. There are no words that describe how much time I spent working on this project, and how much I appreciated anyone following me on the Fediverse. Shoutouts to:
1) Benjamin Hollon (For his work on [readable.css](https://readable-css.freedomtowrite.org/) and his support on the fediverse.
* [Website](https://benjaminhollon.com/)
* [Fediverse](https://alpha.polymaths.social/@amin)