(Ebook) Learning PHP, MySQL & JavaScript by Robin Nixon ISBN 9781491918661, 1491918667 all chapter instant download
(Ebook) Learning PHP, MySQL & JavaScript by Robin Nixon ISBN 9781491918661, 1491918667 all chapter instant download
https://ebooknice.com/product/learning-php-mysql-and-
javascript-1216936
ebooknice.com
(Ebook) Learning PHP MySQL JavaScript and CSS by Robin Nixon ISBN
9781449319267, 1449319262
https://ebooknice.com/product/learning-php-mysql-javascript-and-
css-2618790
ebooknice.com
https://ebooknice.com/product/learning-php-mysql-javascript-early-
release-24129590
ebooknice.com
(Ebook) Learning PHP, MySQL & JavaScript - With jQuery, CSS & HTML5 by
Robin Nixon ISBN 9781491978917, 1491978910
https://ebooknice.com/product/learning-php-mysql-javascript-with-
jquery-css-html5-7294746
ebooknice.com
(Ebook) Learning PHP, MySQL & JavaScript, 6th Edition by Robin Nixon
ISBN 9781492093800, 9781492093824, 1492093807, 1492093823
https://ebooknice.com/product/learning-php-mysql-javascript-6th-
edition-23267530
ebooknice.com
(Ebook) Learning PHP, MySQL & JavaScript, 7th Edition by Robin Nixon
ISBN 9781098152352, 9781098152291, 1098152352, 1098152298
https://ebooknice.com/product/learning-php-mysql-javascript-7th-
edition-54117148
ebooknice.com
(Ebook) Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5
(Early Release 5th) by Robin Nixon ISBN 9781491978917, 1491978910
https://ebooknice.com/product/learning-php-mysql-javascript-with-
jquery-css-html5-early-release-5th-6855160
ebooknice.com
(Ebook) Learning PHP, MySQL, JavaScript, CSS & HTML5, Third Edition: A
Step-by-Step Guide to Creating Dynamic Websites by Robin Nixon ISBN
9781491949467, 1491949465
https://ebooknice.com/product/learning-php-mysql-javascript-css-
html5-third-edition-a-step-by-step-guide-to-creating-dynamic-
websites-4724548
ebooknice.com
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
ebooknice.com
4t
h
wi
Ed jQue
th
Learning PHP, MySQL & JavaScript
iti r y
on
FOURTH EDITION
Build interactive, data-driven websites with the potent combination of
open-source technologies and web standards, even if you have only basic bookisthata great
“This beginner's
introduces
Learning
■■
programming sites, including a basic
■■ Explore MySQL, from database structure to complex queries social networking site. ”
PHP, MySQL
■■ Use the MySQLi Extension, PHP’s improved MySQL interface —Albert Wiersch
developer of CSE HTML Validator
■■ Create dynamic PHP web pages that tailor themselves to
the user
■■ Manage cookies and sessions, and maintain a high level
of security
& JavaScript
■■ Master the JavaScript language—and enhance it with jQuery
■■ Use Ajax calls for background browser/server communication
■■ Acquire CSS2 & CSS3 skills for professionally styling your
web pages
■■ Implement all of the new HTML5 features, including
geolocation, audio, video, and the canvas
WITH JQUERY, CSS & HTML5
Robin Nixon, an IT journalist who has written hundreds of articles and several
books on computing, has developed numerous websites using open source tools,
specializing in the technologies featured in this book. Robin has worked with and
written about computers since the early 1980s.
WEB DEVELOPMENT
Twitter: @oreillymedia Nixon
facebook.com/oreilly
US $49.99 CAN $52.99
ISBN: 978-1-491-91866-1
Robin Nixon
4t
h
wi
Ed jQue
th
Learning PHP, MySQL & JavaScript
iti r y
on
FOURTH EDITION
Build interactive, data-driven websites with the potent combination of
open-source technologies and web standards, even if you have only basic bookisthata great
“This beginner's
introduces
Learning
■■
programming sites, including a basic
■■ Explore MySQL, from database structure to complex queries social networking site. ”
PHP, MySQL
■■ Use the MySQLi Extension, PHP’s improved MySQL interface —Albert Wiersch
developer of CSE HTML Validator
■■ Create dynamic PHP web pages that tailor themselves to
the user
■■ Manage cookies and sessions, and maintain a high level
of security
& JavaScript
■■ Master the JavaScript language—and enhance it with jQuery
■■ Use Ajax calls for background browser/server communication
■■ Acquire CSS2 & CSS3 skills for professionally styling your
web pages
■■ Implement all of the new HTML5 features, including
geolocation, audio, video, and the canvas
WITH JQUERY, CSS & HTML5
Robin Nixon, an IT journalist who has written hundreds of articles and several
books on computing, has developed numerous websites using open source tools,
specializing in the technologies featured in this book. Robin has worked with and
written about computers since the early 1980s.
WEB DEVELOPMENT
Twitter: @oreillymedia Nixon
facebook.com/oreilly
US $49.99 CAN $52.99
ISBN: 978-1-491-91866-1
Robin Nixon
FOURTH EDITION
Robin Nixon
Learning PHP, MySQL & JavaScript
With jQuery, CSS & HTML5
by Robin Nixon
Copyright © 2015 Robin Nixon. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning PHP, MySQL & JavaScript, the
cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-491-91866-1
[LSI]
For Julie
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
v
Questions 33
3. Introduction to PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Incorporating PHP Within HTML 35
This Book’s Examples 37
The Structure of PHP 38
Using Comments 38
Basic Syntax 39
Variables 40
Operators 45
Variable Assignment 48
Multiple-Line Commands 50
Variable Typing 52
Constants 53
Predefined Constants 54
The Difference Between the echo and print Commands 55
Functions 55
Variable Scope 56
Questions 62
vi | Table of Contents
Dynamic Linking in Action 92
Questions 93
Table of Contents | ix
Deleting a Record 244
Displaying the Form 245
Querying the Database 246
Running the Program 247
Practical MySQL 248
Creating a Table 248
Describing a Table 249
Dropping a Table 250
Adding Data 250
Retrieving Data 251
Updating Data 251
Deleting Data 252
Using AUTO_INCREMENT 252
Performing Additional Queries 254
Preventing Hacking Attempts 255
Steps You Can Take 256
Using Placeholders 257
Preventing HTML Injection 259
Using mysqli Procedurally 261
Questions 263
x | Table of Contents
The number and range Input Types 285
Date and Time Pickers 285
Questions 285
Table of Contents | xi
Local Variables 323
The Document Object Model 324
But It’s Not That Simple 326
Using the DOM 327
About document.write 328
Using console.log 328
Using alert 328
Writing into Elements 329
Using document.write 329
Questions 329
Table of Contents | xv
3D Transformations 473
Transitions 474
Properties to Transition 474
Transition Duration 475
Transition Delay 475
Transition Timing 475
Shorthand Syntax 476
Questions 477
xx | Table of Contents
Processing the Image 668
Displaying the Current Profile 669
members.php 672
Viewing a User’s Profile 672
Adding and Dropping Friends 672
Listing All Members 672
friends.php 675
messages.php 678
logout.php 681
styles.css 682
javascript.js 685
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
The combination of PHP and MySQL is the most convenient approach to dynamic,
database-driven web design, holding its own in the face of challenges from integrated
frameworks—such as Ruby on Rails—that are harder to learn. Due to its open source
roots (unlike the competing Microsoft .NET Framework), it is free to implement and
is therefore an extremely popular option for web development.
Any would-be developer on a Unix/Linux or even a Windows/Apache platform will
need to master these technologies. And, combined with the partner technologies of
JavaScript, jQuery, CSS, and HTML5, you will be able to create websites of the caliber
of industry standards like Facebook, Twitter, and Gmail.
Audience
This book is for people who wish to learn how to create effective and dynamic web‐
sites. This may include webmasters or graphic designers who are already creating
static websites but wish to take their skills to the next level, as well as high school and
college students, recent graduates, and self-taught individuals.
In fact, anyone ready to learn the fundamentals behind the Web 2.0 technology
known as Ajax will obtain a thorough grounding in all of these core technologies:
PHP, MySQL, JavaScript, CSS, and HTML5, and learn the basics of the jQuery library
too.
xxiii
Organization of This Book
The chapters in this book are written in a specific order, first introducing all of the
core technologies it covers and then walking you through their installation on a web
development server so that you will be ready to work through the examples.
In the first section, you will gain a grounding in the PHP programming language,
covering the basics of syntax, arrays, functions, and object-oriented programming.
Then, with PHP under your belt, you will move on to an introduction to the MySQL
database system, where you will learn everything from how MySQL databases are
structured to how to generate complex queries.
After that, you will learn how you can combine PHP and MySQL to start creating
your own dynamic web pages by integrating forms and other HTML features. Follow‐
ing that, you will get down to the nitty-gritty practical aspects of PHP and MySQL
development by learning a variety of useful functions and how to manage cookies
and sessions, as well as how to maintain a high level of security.
In the next few chapters, you will gain a thorough grounding in JavaScript, from sim‐
ple functions and event handling to accessing the Document Object Model and in-
browser validation and error handling, plus a comprehensive primer on using the
popular jQuery library for JavaScript.
With an understanding of all three of these core technologies, you will then learn how
to make behind-the-scenes Ajax calls and turn your websites into highly dynamic
environments.
Next, you’ll spend two chapters learning all about using CSS to style and lay out your
web pages, before moving on to the final section on the new features built into
HTML5, including geolocation, audio, video, and the canvas. After this, you’ll put
together everything you’ve learned in a complete set of programs that together consti‐
tute a fully functional social networking website.
Along the way, you’ll find plenty of advice on good programming practices and tips
that could help you find and solve hard-to-detect programming errors. There are also
plenty of links to websites containing further details on the topics covered.
Supporting Books
Once you have learned to develop using PHP, MySQL, JavaScript, CSS, and HTML5,
you will be ready to take your skills to the next level using the following O’Reilly ref‐
erence books. To learn more about any of these titles, simply enter the ISBN shown
next to it into the search box at http://oreilly.com or at any good online book seller’s
website.
xxiv | Preface
• Dynamic HTML: The Definitive Reference (9780596527402) by Danny Goodman
• PHP in a Nutshell (9780596100674) by Paul Hudson
• MySQL in a Nutshell (9780596514334) by Russell Dyer
• JavaScript: The Definitive Guide (9780596805524) by David Flanagan
• CSS: The Definitive Guide (9780596527334) by Eric A. Myer
• HTML5: The Missing Manual (9781449363260) by Matthew MacDonald
Preface | xxv
need to contact us for permission unless you’re reproducing a significant portion of
the code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples
from O’Reilly books does require permission. Answering a question by citing this
book and quoting example code does not require permission. Incorporating a signifi‐
cant amount of example code from this book into your product’s documentation does
require permission. There is a companion website to this book at http://lpmj.net,
where you can download all the examples from this book in a single zip file.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Learning PHP, MySQL & JavaScript,
4th Edition by Robin Nixon (O’Reilly). Copyright 2015 Robin Nixon,
978-1-4919-1866-1.”
If you feel your use of code examples falls outside fair use or the permission given
above, feel free to contact us at permissions@oreilly.com.
Technology professionals, software developers, web designers, and business and crea‐
tive professionals use Safari Books Online as their primary resource for research,
problem solving, learning, and certification training.
Safari Books Online offers a range of plans and pricing for enterprise, government,
education, and individuals.
Members have access to thousands of books, training videos, and prepublication
manuscripts in one fully searchable database from publishers like O’Reilly Media,
Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que,
Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐
mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders,
McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more
information about Safari Books Online, please visit us online.
xxvi | Preface
How to Contact Us
Please address comments and questions concerning this book to the publisher:
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at http://bit.ly/lpmjch_4e.
To comment or ask technical questions about this book, send email to bookques‐
tions@oreilly.com.
For more information about our books, courses, conferences, and news, see our web‐
site at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
I would like to once again thank my editor, Andy Oram, and everyone who worked
so hard on this book, including Albert Wiersch for his comprehensive technical
review, Nicole Shelby for overseeing production, Rachel Monaghan for her copy edit‐
ing, Sharon Wilkey for proofreading, Robert Romano for his original illustrations,
Rebecca Demarest for her new illustrations, David Futato for interior design, Lucie
Haskins for creating the index, Karen Montgomery for the original sugar glider front
cover design, Randy Comer for the latest book cover, and everyone else too numer‐
ous to name who submitted errata and offered suggestions for this new edition.
Preface | xxvii
CHAPTER 1
Introduction to Dynamic Web Content
The World Wide Web is a constantly evolving network that has already traveled far
beyond its conception in the early 1990s, when it was created to solve a specific prob‐
lem. State-of-the-art experiments at CERN (the European Laboratory for Particle
Physics—now best known as the operator of the Large Hadron Collider) were pro‐
ducing incredible amounts of data—so much that the data was proving unwieldy to
distribute to the participating scientists who were spread out across the world.
At this time, the Internet was already in place, with several hundred thousand com‐
puters connected to it, so Tim Berners-Lee (a CERN fellow) devised a method of nav‐
igating between them using a hyperlinking framework, which came to be known as
Hypertext Transfer Protocol, or HTTP. He also created a markup language called
Hypertext Markup Language, or HTML. To bring these together, he wrote the first
web browser and web server, tools that we now take for granted.
But back then, the concept was revolutionary. The most connectivity so far experi‐
enced by at-home modem users was dialing up and connecting to a bulletin board
that was hosted by a single computer, where you could communicate and swap data
only with other users of that service. Consequently, you needed to be a member of
many bulletin board systems in order to effectively communicate electronically with
your colleagues and friends.
But Berners-Lee changed all that in one fell swoop, and by the mid-1990s, there were
three major graphical web browsers competing for the attention of 5 million users. It
soon became obvious, though, that something was missing. Yes, pages of text and
graphics with hyperlinks to take you to other pages was a brilliant concept, but the
results didn’t reflect the instantaneous potential of computers and the Internet to
meet the particular needs of each user with dynamically changing content. Using the
Web was a very dry and plain experience, even if we did now have scrolling text and
animated GIFs!
1
Shopping carts, search engines, and social networks have clearly altered how we use
the Web. In this chapter, we’ll take a brief look at the various components that make
up the Web, and the software that helps make it a rich and dynamic experience.
For an average web page, this process takes place once for each object within the
page: a graphic, an embedded video or Flash file, and even a CSS template.
In step 2, notice that the browser looked up the IP address of server.com. Every
machine attached to the Internet has an IP address—your computer included. But we
generally access web servers by name, such as google.com. As you probably know, the
browser consults an additional Internet service called the Domain Name Service
Although it’s helpful to be aware of this process so that you know how the three ele‐
ments work together, in practice you don’t really need to concern yourself with these
details, because they all happen automatically.
HTML pages returned to the browser in each example may well contain JavaScript,
which will be interpreted locally by the client, and which could initiate another
request—the same way embedded objects such as images would.
Using PHP
With PHP, it’s a simple matter to embed dynamic activity in web pages. When you
give pages the .php extension, they have instant access to the scripting language. From
a developer’s point of view, all you have to do is write code such as the following:
<?php
echo " Today is " . date("l") . ". ";
?>
The opening <?php tells the web server to allow the PHP program to interpret all the
following code up to the ?> tag. Outside of this construct, everything is sent to the
client as direct HTML. So the text Here's the latest news. is simply output to the
browser; within the PHP tags, the built-in date function displays the current day of
the week according to the server’s system time.
The final output of the two parts looks like this:
Today is Wednesday. Here's the latest news.
PHP is a flexible language, and some people prefer to place the PHP construct
directly next to PHP code, like this:
Today is <?php echo date("l"); ?>. Here's the latest news.
There are also other ways of formatting and outputting information, which I’ll
explain in the chapters on PHP. The point is that with PHP, web developers have a
scripting language that, although not as fast as compiling your code in C or a similar
language, is incredibly speedy and also integrates seamlessly with HTML markup.
If you intend to enter the PHP examples in this book to work along
with me, you must remember to add <?php in front and ?> after
them to ensure that the PHP interpreter processes them. To facili‐
tate this, you may wish to prepare a file called example.php with
those tags in place.
Using PHP, you have unlimited control over your web server. Whether you need to
modify HTML on the fly, process a credit card, add user details to a database, or fetch
Using MySQL
Of course, there’s not a lot of point to being able to change HTML output dynami‐
cally unless you also have a means to track the changes that users make as they use
your website. In the early days of the Web, many sites used “flat” text files to store
data such as usernames and passwords. But this approach could cause problems if the
file wasn’t correctly locked against corruption from multiple simultaneous accesses.
Also, a flat file can get only so big before it becomes unwieldy to manage—not to
mention the difficulty of trying to merge files and perform complex searches in any
kind of reasonable time.
That’s where relational databases with structured querying become essential. And
MySQL, being free to use and installed on vast numbers of Internet web servers, rises
superbly to the occasion. It is a robust and exceptionally fast database management
system that uses English-like commands.
The highest level of MySQL structure is a database, within which you can have one
or more tables that contain your data. For example, let’s suppose you are working on
a table called users, within which you have created columns for surname, firstname,
and email, and you now wish to add another user. One command that you might use
to do this is as follows:
INSERT INTO users VALUES('Smith', 'John', 'jsmith@mysite.com');
Of course, as mentioned earlier, you will have issued other commands to create the
database and table and to set up all the correct fields, but the INSERT command here
shows how simple it can be to add new data to a database. INSERT is an example of
Structured Query Language (SQL), a language designed in the early 1970s and remi‐
niscent of one of the oldest programming languages, COBOL. It is well suited, how‐
ever, to database queries, which is why it is still in use after all this time.
It’s equally easy to look up data. Let’s assume that you have an email address for a user
and need to look up that person’s name. To do this, you could issue a MySQL query
such as the following:
SELECT surname,firstname FROM users WHERE email='jsmith@mysite.com';
MySQL will then return Smith, John and any other pairs of names that may be asso‐
ciated with that email address in the database.
As you’d expect, there’s quite a bit more that you can do with MySQL than just simple
INSERT and SELECT commands. For example, you can join multiple tables according
to various criteria, ask for results in a variety of orders, make partial matches when
Using JavaScript
The oldest of the three core technologies in this book, JavaScript, was created to
enable scripting access to all the elements of an HTML document. In other words, it
provides a means for dynamic user interaction such as checking email address valid‐
ity in input forms, and displaying prompts such as “Did you really mean that?”
(although it cannot be relied upon for security, which should always be performed on
the web server).
Combined with CSS (see the following section), JavaScript is the power behind
dynamic web pages that change in front of your eyes rather than when a new page is
returned by the server.
However, JavaScript can also be tricky to use, due to some major differences in the
ways different browser designers have chosen to implement it. This mainly came
about when some manufacturers tried to put additional functionality into their
browsers at the expense of compatibility with their rivals.
Thankfully, the developers have mostly now come to their senses and have realized
the need for full compatibility with one another, so they don’t have to write multi-
exception code. But there remain millions of legacy browsers that will be in use for a
good many years to come. Luckily, there are solutions for the incompatibility prob‐
lems, and later in this book we’ll look at libraries and techniques that enable you to
safely ignore these differences.
For now, let’s take a look at how to use basic JavaScript, accepted by all browsers:
<script type="text/javascript">
document.write("Today is " + Date() );
</script>
This code snippet tells the web browser to interpret everything within the script tags
as JavaScript, which the browser then does by writing the text Today is to the current
document, along with the date, by using the JavaScript function Date. The result will
look something like this:
Today is Sun Jan 01 2017 01:23:45
Using CSS
With the emergence of the CSS3 standard in recent years, CSS now offers a level of
dynamic interactivity previously supported only by JavaScript. For example, not only
can you style any HTML element to change its dimensions, colors, borders, spacing,
and so on, but now you can also add animated transitions and transformations to
your web pages, using only a few lines of CSS.
Using CSS can be as simple as inserting a few rules between <style> and </style>
tags in the head of a web page, like this:
<style>
p {
text-align:justify;
font-family:Helvetica;
}
</style>
These rules will change the default text alignment of the <p> tag so that paragraphs
contained in it will be fully justified and will use the Helvetica font.
New APIs
Such as the <canvas> element for writing and drawing on a graphics canvas, <audio>
and <video> elements, offline web applications, microdata, and local storage.
One of the little things I like about the HTML5 specification is that
XHTML syntax is no longer required for self-closing elements. In
the past, you could display a line break using the <br> element.
Then, to ensure future compatibility with XHTML (the planned
replacement for HTML that never happened), this was changed to
<br />, in which a closing / character was added (since all ele‐
ments were expected to include a closing tag featuring this charac‐
ter). But now things have gone full circle, and you can use either
version of these types of element. So, for the sake of brevity and
fewer keystrokes, in this book I have reverted to the former style of
<br>, <hr>, and so on.
The steps involved in this Ajax process would be similar to the following:
1. The server outputs the HTML to create the web form, which asks for the neces‐
sary details, such as username, first name, last name, and email address.
2. At the same time, the server attaches some JavaScript to the HTML to monitor
the username input box and check for two things: (a) whether some text has been
typed into it, and (b) whether the input has been deselected because the user has
clicked on another input box.
3. Once the text has been entered and the field deselected, in the background the
JavaScript code passes the username that was entered back to a PHP script on the
web server and awaits a response.
4. The web server looks up the username and replies back to the JavaScript regard‐
ing whether that name has already been taken.
5. The JavaScript then places an indication next to the username input box to show
whether the name is one available to the user—perhaps a green checkmark or a
red cross graphic, along with some text.
6. If the username is not available and the user still submits the form, the JavaScript
interrupts the submission and reemphasizes (perhaps with a larger graphic
and/or an alert box) that the user needs to choose another username.
7. Optionally, an improved version of this process could even look at the username
requested by the user and suggest an alternative that is currently available.
Questions
1. What four components (at the minimum) are needed to create a fully dynamic
web page?
2. What does HTML stand for?
3. Why does the name MySQL contain the letters SQL?
4. PHP and JavaScript are both programming languages that generate dynamic
results for web pages. What is their main difference, and why would you use both
of them?
5. What does CSS stand for?
6. List three major new elements introduced in HTML5.
7. If you encounter a bug (which is rare) in one of the open source tools, how do
you think you could get it fixed?
See Chapter 1 Answers in Appendix A for the answers to these questions.
If you wish to develop Internet applications but don’t have your own development
server, you will have to upload every modification you make to a server somewhere
else on the Web before you can test it.
Even on a fast broadband connection, this can still represent a significant slowdown
in development time. On a local computer, however, testing can be as easy as saving
an update (usually just a matter of clicking once on an icon) and then hitting the
Refresh button in your browser.
Another advantage of a development server is that you don’t have to worry about
embarrassing errors or security problems while you’re writing and testing, whereas
you need to be aware of what people may see or do with your application when it’s on
a public website. It’s best to iron everything out while you’re still on a home or small
office system, presumably protected by firewalls and other safeguards.
Once you have your own development server, you’ll wonder how you ever managed
without one, and it’s easy to set one up. Just follow the steps in the following sections,
using the appropriate instructions for a PC, a Mac, or a Linux system.
In this chapter, we cover just the server side of the web experience, as described in
Chapter 1. But to test the results of your work—particularly when we start using Java‐
Script, CSS, and HTML5 later in this book—you should also have an instance of
every major web browser running on some system convenient to you. Whenever pos‐
sible, the list of browsers should include at least Internet Explorer, Mozilla Firefox,
Opera, Safari, and Google Chrome. If you plan to ensure that your sites look good on
mobile devices too, you should try to arrange access to a wide range of Apple iOS and
Google Android phones and tablets.
15
What Is a WAMP, MAMP, or LAMP?
WAMP, MAMP, and LAMP are abbreviations for “Windows, Apache, MySQL, and
PHP,” “Mac, Apache, MySQL, and PHP,” and “Linux, Apache, MySQL, and PHP.”
These abbreviations describe a fully functioning setup used for developing dynamic
Internet web pages.
WAMPs, MAMPs, and LAMPs come in the form of a package that binds the bundled
programs together so that you don’t have to install and set them up separately. This
means you can simply download and install a single program, and follow a few easy
prompts, to get your web development server up and running in the quickest time
with a minimum hassle.
During installation, several default settings are created for you. The security configu‐
rations of such an installation will not be as tight as on a production web server,
because it is optimized for local use. For these reasons, you should never install such a
setup as a production server.
But for developing and testing websites and applications, one of these installations
should be entirely sufficient.
I recommend that you always download the latest stable release (in this instance, it’s
1.8.3), and there is a direct download link for Windows, OS X, and Linux on the main
page.
During the lifetime of this edition, some of the screens and options
shown in the following walk-through may change. If so, just use
your common sense to proceed in as similar a manner as possible
to the sequence of actions described.
Once you’ve downloaded the installer, run it to bring up the window shown in
Figure 2-2. Before arriving at that window, though, if you use an anti-virus program
or have User Account Control activated on Windows, you may first be shown one or
more advisory notices, and will have to click Yes and/or OK to continue installation.
Click Next and then uncheck any of the components shown in Figure 2-3 that you
don’t need. For example, at the minimum for this book you will want to keep Apache,
MySQL, PHP, and PHPMyAdmin checked. The other features are not covered in this
book, but you can get more details on all of these, plus the core XAMPP technologies,
at http://apachefriends.org/faq_windows.html.
Clicking Next brings up the screen in Figure 2-4, in which you should choose a folder
for the installation. You are recommended to accept the default provided unless you
have a good reason to choose a different one. In this book, the default location is
assumed. If the folder you choose exists and is not empty, you will be unable to use it.
Clicking Next brings up the screen in Figure 2-5 with a checkbox already checked
(which you can uncheck) for supplying information on adding free installers for
related products in a new web browser window or tab. After you choose whether or
not to receive this information, click the Next button.
Having supplied the basic information required by the installer, you will arrive at the
screen in Figure 2-6. Setup is ready to start, so click the Next button.
Figure 2-6. Accept the default values offered for the ports
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