PHP for the Web
PHP for the Web
Learn PHP without a framework
About the Book
"PHP for the Web is a terrific introduction on how to use modern PHP effectively. The book is well suited for anyone with a basic knowledge of PHP or someone coming from another programming language. I was able to easily follow along, and I developed a good sense of the strengths of PHP for web development. I am currently learning more about object-oriented PHP, and frameworks like Symfony, and I felt that this book gave me a solid foundation." -- Jason Pollard
This book is for people who want to learn to build web applications with PHP. It doesn't focus on PHP programming, but shows how PHP can be used to serve dynamic web pages. You'll discover all the basic ingredients of a web application.
We won't use a framework like Symfony or Laravel, we'll only work with plain PHP. This allows us to focus on the core ideas, instead of how a particular framework implements them.
After reading this book you'll know how to use multiple web technologies like POST requests, forms, sessions, and redirects to build a CRUD application with an authentication system.
Each chapter comes with a set of Quiz questions so you can test your knowledge. On top of the practical exercises in the book there are 5 additional Challenges that help you practice the techniques from this book on your own. The solutions are available on GitHub.
"An excellent book to learn or refresh the base of PHP" -- @lambeletjp
Educative.io has created an interactive course based on this book. You can write PHP in your browser and they can even run the code for you. Register here: https://www.educative.io/courses/php-web-learn-php-without-framework/
Get 6 copies to give away to friends and co-workers
- Who should read this book?
- PHP Runtime
- An IDE that works well with PHP
- An overview of the contents
- The source code
- Feedback and suggestions
- 31 January 2021
- Shortened several lines in code samples that were too long to show on the page and were cut in two by a backslash, which produces incorrect code.
1. Serving resources
- Serving an index.html file with the built-in web server
- Adding a favicon
- Security announcement: The project root should not be the document root
- Communication between the browser and the server
2. Serving PHP scripts
- The response: status, headers and body
- Building up a response
- Linking to other pages
- Passing values between requests
- Security announcement: user input can’t be trusted
- Submitting form data as query parameters
- Security announcement: Always use output escaping
- Adding a select element to the form
- Submitting data via the request body
- Setting a cookie
- Using a cookie
- Set-Cookie is a response header, Cookie a request header
Redirecting after processing a
- Security announcement: cookies can be manipulated without you knowing
- Session files and serialized data
- Flash messages
- Using flash messages everywhere
- A secret page
- Setting up a login form
- Validating the username and the password
- Logging out
7. Project structure
- Header and footer snippets
- Passing variables to snippets
- Flash messages revisited
- From .html to .php
- Adding navigation
- Adding a stylesheet
8. CRUD part 1: Create
- Saving JSON-encoded data in a file
- Adding a tour
- Form validation
- Showing the submitted data in the form
- Listing tours
9. CRUD part 2: The rest
- Introducing some reusable elements
- Editing tour data
- Deleting tours
10. File uploads
- Adding a details page
- Uploading a file
- Processing the file upload
- Showing the uploaded picture
- Replacing the existing image
- Form validation for file uploads
11. Error handling
- Producing an error
- Using different configuration settings in production
- PHP errors
12. Automated testing
- Using Composer to install testing tools
- A first test
- Creating our first browser test
- A test for the pictures page
- Starting with a clean slate
- Troubleshooting and suggestions
- Object-oriented programming
- Parting words
- Appendix A: Installing PHP on Windows
Appendix B: Answers to the quiz questions
- Chapter 1
- Chapter 2
- Chapter 3
- Chapter 4
- Chapter 5
- Chapter 6
- Chapter 7
- Chapter 8
- Chapter 9
- Chapter 10
- Chapter 11
- Chapter 12
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.