Book Image

Beginning PHP

By : David Carr, Markus Gray
Book Image

Beginning PHP

By: David Carr, Markus Gray

Overview of this book

<p>PHP is the preferred server-side scripting language for tech giants such as Facebook, Wikipedia, and Tumblr despite full-stack JavaScript gaining popularity with upcoming developers. This is because PHP performs better when dealing with heavy computations on the back end. In this book, you’ll learn everything you need to get up and running with the latest version of PHP, including package management with tools such as composer, secure database operations, and a whole host of other best practices that will help you stay a step ahead of traditional programmers. </p><p> </p><p></p>
Table of Contents (12 chapters)
Beginning PHP
Contributors
Preface
Free Chapter
1
Getting Started with PHP
2
Arrays and Loops
Index

Preface

Developing a website is a priority these days in order for your business to have a presence on the internet. Design and development are foundational steps for any website. PHP is commonly used for website and web application development. PHP is a general purpose, server-side scripting language that's designed to make dynamic pages and applications. PHP as a web development option is secure, fast, and reliable, and also offers lots more advantages that make it accessible to a lot of people. We should consider what has made PHP one of the most widely used programming languages in the web industry.

This book gets you up to speed by starting with basic concepts, such as variables, data types, arrays, and loops. It then progresses to more advanced concepts, such as building your own frameworks and creating your app.

The book has been designed for the purpose of reducing the gap between learning and implementation. It provides a lot of real business case scenarios, which will help you to understand the concepts and get started with writing PHP programs as soon as they complete the book.

What This Book Covers

Chapter 1, Getting Started with PHP, covers the fundamentals of using the PHP programming language. In this chapter, you'll learn basic PHP syntax and program structure. You'll also learn how to use variables, data types, operators, and conditionals.

Chapter 2, Arrays and Loops, shows you how to use the flow control structures. We will specifically cover loops and arrays in this chapter.

Chapter 3, Functions and Classes, teaches you to identify how to define and call functions. We will also cover how to create classes, and how to use the classes and functions together.

Chapter 4, Data Operations, teaches you how to handle input from users and printing outcomes back to them, handling errors gracefully, and learning the basics of using the MySQL database.

Chapter 5, Building a PHP Web Application, teaches you to apply OOP concepts in a framework. We will cover error reporting using the Whoops library and will learn how to handle those errors. We will also cover how to manage and structure our application in a framework.

Chapter 6, Building a PHP Framework, teaches you to build an MVC framework from scratch. Starting from an empty directory, we will build an entire working framework as a starting point for more complex applications.

Chapter 7, Authentication and User Management, teaches you the security aspect of the project, that is, authentication. We will be building login forms which interact with the database to verify the identity of the users. We will also cover how to set up a password recovery mechanism in our application.

Chapter 8, Building a Contacts Management System, teaches you to build a contacts CRUD (Create, Read, Update, and Delete) section, which will have a view page to view an individual contact. We will also be building the comments system for our contact application.

What You Need for This Book

Hardware

The minimum hardware requirements are as follows:

  • Windows 7 64-bit

  • Processor: Intel Core processor

  • Memory: 1 GB RAM

  • An internet connection

Software

  • WAMP server for Windows

  • LAMP server for Linux

  • MAMP server for Mac

  • Browser: the latest version of one or more browsers (Internet Explorer 11, or Chrome 54.0.2840 or newer is recommended)

  • A text editor such as Notepad or Notepad++

Who This Book Is For

This book is for anyone interested in learning the fundamentals of PHP programming. For the best experience, you should have basic knowledge of HTML, CSS, JavaScript, and MySQL.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Create a new file and name it syntax.php."

Folder names, filenames, file extensions, pathnames, include file names in text are shown as follows: "To remove an element from an array, use the unset function.

A block of code is set as follows:

<?php  
  echo "Hello World"; 
?> 

Any command-line input or output is written as follows:

php syntax.php

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "So, when we click on the Submit button, the data will be submitted."

Important new programming terms are shown in bold. Conceptual terms are shown in italics.

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Installation and Setup

Before you start this book, we'll install a PHP server, such as WAMP, and a text editor, such as Atom.

Installing WAMP on Windows

  1. Visit http://www.wampserver.com/en/ in your browser.

  2. Click on WAMP SERVER 64 bits or WAMP SERVER 32 bits, depending on your system.

  3. Next, there will be a popup, which will give you a couple of warnings. Click on download directly.

  4. Open the installer after download.

  5. Follow the steps in the installer and that's it! Your WAMP server is ready.

Installing LAMP in Linux

  1. Visit https://bitnami.com/stack/lamp/installer in your browser.

  2. Under Linux, click on the Download button.

  3. Next, there will be a popup, which will give you options for logging in. Just click on No thanks, just take me to the download option.

  4. Open the installer after download.

  5. Follow the steps in the installer and that's it! Your LAMP server is ready.

Installing MAMP for MAC OS

  1. Visit https://www.mamp.info/en/ in your browser.

  2. Under MAMP, click on DOWNLOAD button.

  3. In the next page, click on macOS click on Download button.

  4. Open the installer after download.

  5. Follow the steps in the installer and that's it! Your MAMP server is ready.

Downloading the Example Code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

The code bundle for the book is also hosted on GitHub at https://github.com/TrainingByPackt/Beginning-PHP/. In case there's an update to the code, it will be updated on the existing GitHub repository.