Lesson 16 - Putting PHP interfaces into practice - GuestBook
In the previous lesson, Interfaces and abstract classes in PHP, we went over the theoretical aspects of interfaces and abstract classes. Now, as is tradition here at ICT.social, we're going to put what we learned to proper use.
We'll program a simple guestbook or rather a shout-board. I'm sure you all have seen widgets like this somewhere on the web. They're a spot on the website, where the last couple of messages are displayed along with a form that submits a new message. To protect us from spam, our messenger will use a captcha (an antispam mechanism). Our captcha will require an interface because we're going to make it modular.
Create a new project folder, wherein you'll create a "classes" folder and an index.php file.
First and foremost, we'll set up the database. Create a new table and name it "message". This table will contain guestbook messages, and will have the following columns:
- message_id (int, primary, AI)
- created (DATETIME)
- name (varchar 50)
- content (TEXT)
Add the table using PHPMyAdmin:
Alternatively, you can use the following creation script:
...End of the preview...
You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.
- Unlimited and permanent access to individual lessons.
- High quality IT knowledge.
- Skills to help you get your dream and well-paid job.
Requested article covers this content:
In this lesson, we'll put our knowledge of OOP in PHP to the test by using interfaces to create a guestbook and modular captchas.
You gain points by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.