Introduction

Learn PHP 7: Object-Oriented Modular Programming using HTML5, CSS3, JavaScript, XML, JSON, and MySQL is intended for use as a beginning level programming book. It is not the goal of this book to cover advanced techniques in the current versions of the PHP programming language. Some knowledge of general programming concepts is expected but no actual programming experience or education is assumed.

All code examples in this book are compatible with PHP 7. Most examples are compatible with PHP 5.6. The newest (as of the publication date) methods (functions) available in PHP have been used to provide the reader with the most current coding techniques. The examples use core methods provided in the PHP language. PHP includes many additional methods to accomplish similar tasks. The reader may, and should, research additional ways of improving security, performance, and other techniques. It is the goal of this book to prompt users to always consider using the most secure and efficient methods of program development. The code in this book provides some examples of using these techniques. The user should remember that no program is 100% secure. The programmer can only strive to make an application as secure as possible. It takes a team of developers, network personnel, security administrators, data center personnel, and others working together to provide the safest environment.

A Different Approach

There are quite a number of PHP books on the market today. What makes this book any different than any other?

· This book uses the concept of “learning by doing,” which shows the reader how to develop applications with conditional statements, loops, arrays, and methods. Over 70 PHP methods (functions) are introduced and demonstrated in coding examples.

· From the very first examples, the reader is introduced to object-oriented programming techniques. Many other books only briefly cover OO programming (if at all) in the final chapters.

· Object-oriented set methods are used to verify and filter user input. Many other books simply show a set method accepting data and storing it.

· A major objective of the book is to convince the reader to create all programs as secure and efficient as possible. The newest password encryption techniques (password_hash) are demonstrated.

· The try and catch methods are introduced to capture exceptions and some errors. The newest versions of PHP have been created to handle exceptions and errors using this approach. Many other books use die or other techniques to shut down a program.

· Multi-tier program design is introduced in the early chapters. This allows the reader to discover what logic and coding should take place in each tier. Many PHP books do not even cover this topic.

· The majority of the examples in the book are used to develop one main application (ABC Canine Shelter Reservation System). As the book progresses, the application is built from the beginning, in stages, showing the reader that application development should be broken into stages. Only after each stage is completed and tested, can the next stage begin. This approach works hand in hand with multi-tier design. Additional programming exercises and a term project are provided to enhance the understanding of development.

· The creation of user, change, and error logs are introduced. This allows the reader to gain an understanding of how to provide backup and recovery ability to keep an application functioning properly when security breaches or exceptions occur.

· The introduction of data objects and the data tier demonstrates to the reader the importance of creating an application that provides the ability to change data storage techniques and data storage location without requiring a major rewrite of the application. XML, JSON, and MySQL examples are provided.

· A natural relationship between PHP, HTML5, CSS3, and JavaScript is demonstrated throughout the book. This relationship is one of the major strengths of PHP.

· Throughout the book, web links are provided to point the user to additional resources to help understand the material or to dig deeper into the subject matter. Updates to link locations are provided on the book’s web site.

Special Note for Teachers

The design of the content of this book provides flexibility in teaching styles and approaches. Each college and university approaches the initial education of programming concepts in different ways. This book provides three different types of programming exercises, which allow teachers to pick and choose what would work best in their environment. “Do It” exercises are provided in each chapter to allow the student to gain hands-on experience with techniques shown by modifying existing examples to produce the desired results. These exercises provide a level of confidence before the student attempts to program exercises at the end of the chapters. In addition, a Term Project is provided that builds an application that uses the same types of algorithms and programming techniques shown in the book.

Teaching tools, including test banks, course outline, and PowerPoint slides are available for use from the book’s web site and from apress.com .

Code Examples, Images, and Links

Every effort has been made to catch any errors in code (and grammar). Please let us know if/when you discover problems in this book. Please send all corrections to Steve Prettyman (steve_prettyman@hotmail.com).

All code examples, images, and links are available for download from apress.com and the following location. You can download code examples from either web site. Copying code from the book may cause errors due to format requirements for publishing.

Book’s web site: www.littleoceanwaves.com/securephp/

Chapter Overview

Chapter 1: An Introduction to PHP 7

After completing this chapter, the student will be able to:

· Understand the difference between LAMP, WAMP, and MAMP

· Successfully install a version of LAMP, WAMP, or MAMP

· Search the Internet for troubleshooting problems

· Explain the difference between a programming language and a scripting language

· Create an error-free simple PHP program

Chapter 2: Interfaces, Platforms, Containers, Three Tier Programming

After completing this chapter, the student will be able to:

· Give examples of platforms or containers that can host PHP programs

· Create a simple, dynamic web application using PHP

· Explain three-tier design and determine what is contained in each tier