[FREE PDF sample] (Ebook) An Introduction to PHP: Learn PHP 8 to Create Dynamic Websites by Mark Simon ISBN B0CSS5DBK4 ebooks
[FREE PDF sample] (Ebook) An Introduction to PHP: Learn PHP 8 to Create Dynamic Websites by Mark Simon ISBN B0CSS5DBK4 ebooks
com
https://ebooknice.com/product/an-introduction-to-php-learn-
php-8-to-create-dynamic-websites-56083930
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
(Ebook) Practical PHP 7, MySQL 8, and MariaDB Website
Databases A Simplified Approach to Developing Database-
Driven Websites - 2nd Ed by Adrian W. West, Steve
Prettyman ISBN 9781484238424, 1484238427
https://ebooknice.com/product/practical-php-7-mysql-8-and-mariadb-
website-databases-a-simplified-approach-to-developing-database-driven-
websites-2nd-ed-35162924
ebooknice.com
https://ebooknice.com/product/php-architect-s-guide-to-php-
security-1970450
ebooknice.com
ebooknice.com
ebooknice.com
https://ebooknice.com/product/node-js-for-php-developers-porting-php-
to-node-js-4078222
ebooknice.com
An Introduction
to PHP
Learn PHP 8 to Create
Dynamic Websites
—
Mark Simon
An Introduction
to PHP
Learn PHP 8 to Create
Dynamic Websites
Mark Simon
An Introduction to PHP: Learn PHP 8 to Create Dynamic Websites
Mark Simon
Ivanhoe VIC, VIC, Australia
ISBN-13 (pbk): 979-8-8688-0176-1 ISBN-13 (electronic): 979-8-8688-0177-8
https://doi.org/10.1007/979-8-8688-0177-8
Acknowledgments�����������������������������������������������������������������������������xxi
Introduction�������������������������������������������������������������������������������������xxiii
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
Preliminary Coding��������������������������������������������������������������������������������������������114
The Data Variables���������������������������������������������������������������������������������������114
Processing POSTed Data and Preliminary Validation�����������������������������������116
Image Validation������������������������������������������������������������������������������������������������118
The $_FILES Array���������������������������������������������������������������������������������������118
Using File Data��������������������������������������������������������������������������������������������119
Checking an Image File�������������������������������������������������������������������������������122
Keeping the File������������������������������������������������������������������������������������������������125
The File Name����������������������������������������������������������������������������������������������126
Lower Case��������������������������������������������������������������������������������������������������128
Replacing Spaces����������������������������������������������������������������������������������������128
Defining the Location����������������������������������������������������������������������������������129
Moving the File��������������������������������������������������������������������������������������������131
Creating Additional Copies��������������������������������������������������������������������������������132
Resized Image Configuration�����������������������������������������������������������������������134
Generating the Resized Copies��������������������������������������������������������������������135
Tidying Up���������������������������������������������������������������������������������������������������������136
Clearing the Error Array�������������������������������������������������������������������������������136
Clearing the Old Values��������������������������������������������������������������������������������137
Summary����������������������������������������������������������������������������������������������������������137
Coming Up���������������������������������������������������������������������������������������������������������138
viii
Table of Contents
ix
Table of Contents
x
Table of Contents
xi
Table of Contents
xii
Table of Contents
Logging Out�������������������������������������������������������������������������������������������������������370
Restricting Access��������������������������������������������������������������������������������������������371
Summary����������������������������������������������������������������������������������������������������������374
Coming Up���������������������������������������������������������������������������������������������������������375
xiii
Table of Contents
xiv
Table of Contents
Index�������������������������������������������������������������������������������������������������613
xv
About the Author
Mark Simon has been involved in training
and education since the beginning of his
career. He started as a teacher of mathematics
and moved into IT consultancy and training.
He has worked with and trained in several
programming and coding languages and
currently focuses on web development and
database languages. When not involved in
work, Mark can be found listening to or playing
music, reading, or just wandering about.
xvii
About the Technical Reviewers
Jeff Friesen is a freelance software developer
and educator conversant in multiple operating
systems, programming languages, and other
technologies. His specialty is Java Standard
Edition.
xix
Acknowledgments
Many of the images used for the sample site come from Wikimedia
Commons (https://commons.wikimedia.org/wiki/Main_Page),
while other photographs are my own and can be used freely for the
purpose. The background pattern comes from Pattern Cooler
(https://patterncooler.com/).
The text, alas, is my own, and I am unable to shift the blame.
xxi
Introduction
When the World Wide Web was invented, it was designed for scientists to
share information with other scientists, which is to say it wasn’t meant to
be exciting. Things have, thankfully, come a long way since then.
At the time, pages were statically created—that is, each page was
crafted one at a time. Fortunately, the web server was designed to be
extensible, and it is possible to interface the server with external software.
The standard way to do this is to use the Common Gateway Interface, or
CGI to its friends.
In the early 1990s, Rasmussen Lerdorf developed a collection of
CGI programs for his Personal Home Page. This grew into what became
Personal Home Page Tools (PHP Tools, for short), version 1. Others began
to get involved, and this grew into version 2.
In the late 1990s, Zeev Suraski and Andi Gutmans rewrote things and
developed version 3, renaming it to PHP: Hypertext Preprocessor. This, in
turn, grew into PHP 4, based on the new Zend Engine, named after Zeev
and Andi. PHP 4 is the earliest version mentioned on the official website,
http://php.net.
Since then, things have moved on. PHP 5 improved on the syntax,
overhauled support for Object-Oriented Programming, and introduced
PHP Data Objects, PDO, to access the database. PHP has always been able
to work with databases, but PDO does it in a much more organized way.
PHP 6 was supposed to add a number of new features, in particular
better Unicode support, but it was taking so long that the improvements
were gradually added to PHP 5, and PHP 6 was absorbed into it.
xxiii
Introduction
All of this is, hopefully, ancient history. PHP 5 has long been retired, as
has PHP 7, which vastly improved performance, including a new JIT (Just
in Time) compiler, and added significant improvements to the syntax.
The current version of PHP is version 8 point something, and PHP 7
and below are regarded as old. The main differences you’ll see include
improved performance, more improvements to the syntax, and significant
steps toward better consistency in the language.
This book, of course, works with PHP 8. Unfortunately, a significant
number of web hosts, quite possibly including yours, are slow to make the
move from a previous version, since that risks breaking some sites which
rely on older features. We’ll allow for that by showing alternative code to
work with older versions.
PHP was never originally meant to be a programming language, and it
shows. Coming from a mixed environment results in some features which
are more like other programming languages and some features which
are more like working with a Unix-like shell. Functions have inconsistent
naming and usage, and the whole appears to be a growing collection of
ideas rather than a planned and organized language.
Things are getting better, but it will still drive many experienced
programmers to distraction. Nevertheless, it all makes some sort of sense,
and it’s not hard to get into the spirit of things.
xxiv
Introduction
To get to know the ideas better, we’ll be working on a sample site, the
files for which you’ll download and install. They have the basic outline,
layout, and styles ready to go, and it will be your job to finish the site with
the PHP you’ll be learning.
You’ll then start writing the code. Chapter 2 looks at how you actually
write PHP and how you can organize your code. In the chapter, you’ll get
the basic principles of PHP programming. Chapter 3 puts the coding into
practice and looks at working with a form and sending an email. Forms
will be a fundamental technique working with PHP, as they will enable you
to send data and maintain it on the web server.
Chapter 4 will concentrate on uploading files to the web server. These
will include image files. The images will eventually be used in an image
gallery, so you’ll also look at manipulating these images to get them ready.
A core part of the website is about the data. In Chapter 5, you’ll look at
connecting to the database and getting the database ready for the back end
of the site. From there, you’ll learn how to add data safely in Chapter 6.
In Chapter 7, you’ll look at working with ZIP files and processing CSV
files. This will enable you to do a bulk upload of data and images for the
image gallery.
The image gallery itself is developed in Chapter 8. You’ll develop skills
in reading the database, fetching images, and preparing HTML content
from the database data.
In Chapter 9, you’ll learn about maintaining the data. Not only will you
be inserting and reading data, you’ll also be editing and deleting some of it.
This gives you complete control over the content of the database.
In Chapter 10, the focus is on security. You’ll learn about how PHP
maintains continuity for individual users and how we manage passwords
and logging in. Chapter 11, on the other hand, focuses on configuring
the site and develops a configuration page which manipulates a
configuration file.
xxv
Introduction
xxvi
CHAPTER 1
Introduction
and Setting Up
Before you get started with learning PHP, you will need to have a working
development environment. Ultimately, PHP will be running from your web
server, either on the Internet or on an intranet. However, for development
(and training) purposes, it makes sense to set up a local web server. This
can be any machine on your network, but it’s very easy to set up everything
you need on your own desktop or laptop computer.
The good thing about web development is that it is culturally agnostic.
It doesn’t matter whether you develop on Macintosh, Windows, or even
Linux: the product will be the same. What does matter is that you have all
the right software in the right place.
2
Chapter 1 Introduction and Setting Up
3
Chapter 1 Introduction and Setting Up
4
Chapter 1 Introduction and Setting Up
The sample project is what you might call a “brochure site.” If you
can imagine what a color glossy brochure would look like if it was
implemented on the Web, it would be something like this.
Here are some of the things you would expect of a brochure site:
• A collection of photos
• A collection of articles
The Tools
Presumably, you’ve already got a computer. It doesn’t matter what the
operating system is, as long as you can install whatever software you need.
5
Chapter 1 Introduction and Setting Up
You’ll also need a copy of the sample project, as we’ll describe in the
Web Server Setup section.
A Coding Editor
Most of the files for a website are text files. There are also images and the
database, but all of your actual coding will involve text.
That means you can edit these files with any old text editor. More
realistically, you’ll want to use a text editor designed for writing code. Here
are the features you’ll want:
6
Chapter 1 Introduction and Setting Up
You may already have your preferred coding editor. If you don’t, you
can try one of these:
• Pulsar: https://pulsar-edit.dev/
• VSCodium: https://vscodium.com/
Both are free, cross-platform, and open source. They also have
additional extension packages available to customize your editor.
If you have another coding editor already, that will do as well.
If you are doing this on Linux, you may prefer not to use the
preinstalled web server and database for learning or development.
One of the following recommended packages also has a version
for Linux.
7
Random documents with unrelated
content Scribd suggests to you:
Ja muutamana päivänä selvisi hänelle eriskummainen seikka: hän
rakasti
Simone Morangea — aivan yksinkertaisesti sanoen!
Simone säpsähti:
— Te?
— Te rakastitte häntä?
— Mutta entä tuo mies… mitä hän teki, mitä hän puhui?
— Hän? toisti hän. — Mitä hän sitten olisi voinut sanoa minulle?
Tuo kaikkihan tapahtui vain minun omassa järjettömässä
mielessäni… Eihän hän tiennyt mitään koko asiasta!
»Minä kerron tuon asian herra Petitbois'ille, hän voi antaa minulle
hyvän neuvon.»
— Jos ei hän olekaan nuori mies, neiti Lise? Jos hän onkin
päinvastoin kiltti vanha ukkeli? Luonnon lapsipuoli, joka olisi hänkin
halunnut olla kaunis, voittaa rakkautta! — raajarikko, joka on
haaveillut avarasta maailmasta, matkoista… elämän onnea vaille
jäänyt olento, vanhus, jolla ei ole ollutkaan nuoruutta…
— Kuten teillä…
(Aihe viuhkamaalauksista.)
Kumpiko heistä sitten oli oikeassa? Sitä olisi minun varsin vaikea
sanoa, niin sekaisin olivat oikeudenjakajat panneet kaikki asiat. Joko
markiisitar — tai kenties herttua. Jollei toinen, niin toinen, — siihen
viittasivat asiakirjat. Eräs syvämietteinen ihmisvihaaja, La
Rochefoucauld, joka varmaankin oli selvillä tämäntapaisista asioista,
on sanonut että riidat saataisiin aina nopeasti ratkaistuiksi, jos
vääryyttä olisi tapahtunut ainoastaan toiselta puolelta. Kuinka lienee
ollutkaan, — joka tapauksessa oli herttuan ja markiisittaren
oikeudenkäyntiä kestänyt jo melkein seitsemän vuotta.
*****
*****
— Hyvä täti, enhän ole vielä jutellut hänelle niin pitkälti kuin hän
kirjoittaa teille, vastasi Doris hymyillen. — Herttuan täytyy olla teihin
kiihkeästi ihastunut, voidakseen sanoa teille niin viehkeällä tavalla
niin paljon miellyttäviä seikkoja, ja luulen… niin kyllä, minä luulen,
että hän tekee teidät onnelliseksi. Hän on herttainen mieleltään ja
lämminsydäminen!
*****
Mutta päivä lähestyi, jolloin kirkon siunauksen piti yhdistää
Troncantiquen ja Souchevieillen suvut.
*****
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com