PHP
Tips and Tricks for Building Modern PHP Apps
Table of Contents
Copyright 2020 by Logan Pratt - All rights reserved.
This document is geared towards providing exact and reliable information in regard to the topic and issue covered. The publication is sold with the idea that the publisher is not required to render accounting, officially permitted or otherwise qualified services. If advice is necessary, legal or professional, a practiced individual in the profession should be ordered.
- From a Declaration of Principles which was accepted and approved equally by a Committee of the American Bar Association and a Committee of Publishers and Associations.
In no way is it legal to reproduce, duplicate, or transmit any part of this document in either electronic means or in printed format. Recording of this publication is strictly prohibited, and any storage of this document is not allowed unless with written permission from the publisher. All rights reserved.
The information provided herein is stated to be truthful and consistent, in that any liability, in terms of inattention or otherwise, by any usage or abuse of any policies, processes, or directions contained within is the solitary and utter responsibility of the recipient reader. Under no circumstances will any legal responsibility or blame be held against the publisher for any reparation, damages, or monetary loss due to the information herein, either directly or indirectly.
Respective authors own all copyrights not held by the publisher.
The information herein is offered for informational purposes solely and is universal as so. The presentation of the information is without a contract or any type of guarantee assurance.
The trademarks that are used are without any consent, and the publication of the trademark is without permission or backing by the trademark owner. All trademarks and brands within this book are for clarifying purposes only and are owned by the owners themselves, not affiliated with this document.
Introduction
This book contains proven steps and strategies on how to code in PHP to create web applications. You will learn about the distinct features of PHP in the form of functional codes that you can use in a PHP editor for practice purposes. I have made sure that youll learn about all the basic and advanced level codes that you will need to create a web app such as a Content Management System (CMS). As MySQL is an integral part of PHP, I have dedicated a chapter on different statements of MySQL, which you can use to operate a database. PHP is hollow without MySQL because each web application requires a database to channelize user information and store it for future usage.
PHP is not too old; we can trace back its origins to 1994 when Rasmus Lerdorf wrote the very first version. It was built, in its initial phases, from the C language as a means of replacing code snippets of Perl that he had been using on the personal homepage that he had. It kept evolving; however, it was 1995 that he released the very first formal as well as the public version of this language. At this point, PHP had been referred to as Personal Homepage Tools. JavaScript was bound to release in 1996 as a client-side language. PHPs release at that time as a server-side language speaks volumes about the tremendous growth in the tools of the Internet that occurred at that time.
In 1998, PHP received its third version that was released by Andi Gutmans and Zeev Suraski. The new version had got its unique name Hypertext Preprocessor. This version awarded PHP sizable popularity. The version 4 of PHP came in 2000 and was referred to as Zend Engine. This version elevated PHP to a level that it had never seen before. It removed certain shortcomings from PHP and made it a fuller language. Version 5 of PHP received its release in 2004 with new features such as an improved version of object-oriented programming and better performance. PHP 7 was released in 2014 and 2015. It further updated PHP for a higher level of web development.
PHP shot to fame when the world got to know that Mark Zuckerberg had used it to create the world-famous application Facebook. When dropped out of Harvard in 2003, Mark adopted this language to create the app, and the Facebook app is still using this language at its backend. Facebook has since developed its own language known as Hack, but it is a version of PHP.
The book contains practical steps to help you understand what happens at the server-side of a web application. It will help you go through the ins and outs of PHP and MySQL that generally go side by side in the creation of a web application. I have divided this chapter into 11 chapters to create ease for the readers. Each chapter of the book deals with a unique topic. I recommend that you download and install a PHP editor or open an online PHP editor for practice purposes while you read the book. You can use the sample codes from the book and understand how they work when they are put in an editor. I hope your journey through the book will be amazing, and you will come out as a knowledgeable person.
The first chapter of the book focuses on the installation of PHP on your computer. It is a complicated process. You should give it a couple of readings to understand how you can do it. The process will not be as much difficult on Linux and Mac OS as it will be on a Windows Operating System. I have explained the topic in a step-by-step order. The first chapter is the installation of the webserver on your operating system, and there are many web servers available in the market. You can choose at will. In the case of this book, I chose to explain the most popular web server of all time that is known as Apache. Apache is a brilliant web server that pairs up with PHP and enhances its performance. When you have downloaded it, you will have to verify Apache. The next step is the installation process. You will find it explained most lucidly and comprehensively. After the installation process completes, you can open Apache and initiate the operations. The final step regarding the webserver is the configuration of Apache. The second half of this chapter focuses on the installation of PHP on your computer system. As it is a server-side language, its installation is a bit tricky and somewhat a tough nut to crack. However, by following the right steps, you can go through it like a breeze. It will be smooth sailing. When you have obtained PHP, you have to verify it. Next comes the task of the configuration of your web server regarding PHP. The chapter ends on explaining the configuration process.
The second chapter of the book focuses on the basics of PHP. I will explain how you should create an HTML page as it is an essential part of PHP. You will be required to embed your PHP code in the HTML document you create. The HTML document will help PHP run the web application. The PHP code will not be visible on the web page when you try to display it. All the code will remain hidden; however, the HTML code will be shown. I will analyze the PHP script for you so that you understand it when you read it in the next sections and write it for practice. This chapter contains valuable information about PHP variables, PHP strings, etc. You will learn how you can use PHP variables for storing information and using it later on.
The third chapter of the book focuses on creating PHP scripts that you would need when you build a web application. The first script, and also one of the most popular in many programming languages, is the conditional statement. A conditional statement can be identified by the keyword if. The if statement comes into play when you have to set more than one condition in the code so that the web application reads through them and acts on them. If the first condition is true, the code doesnt move further and just ends there. If the first condition turns out to be false, the code jumps on to the next condition and runs it. When there are else-if statements, and the first two conditions turn out to be false, the third condition comes into play.