1-Introduction To Dynamic Web Content
1-Introduction To Dynamic Web Content
A dynamic client/server
request/response sequence
1. You enter http://server.com into
your browsers address bar.
2. Your browser looks up the IP
address for server.com.
3. Your browser issues a request to
that address for the web servers
home page.
4. The request crosses the Internet
and arrives at the server.com web
server.
5. The web server, having received the
request, fetches the home page from
its hard
disk.
A dynamic client/server
request/response sequence
6. With the home page now in memory,
the web server notices that it is a file
incorporating
PHP scripting and passes the page to the
PHP interpreter.
7. The PHP interpreter executes the PHP
code.
8. Some of the PHP contains MySQL
statements, which the PHP interpreter
now
passes to the MySQL database engine.
9. The MySQL database returns the
results of the statements back to the PHP
interpreter.
10. The PHP interpreter returns the
results of the executed PHP code, along
with the
results from the MySQL database, to the
web server.
11. The web server returns the page to
the requesting client, which displays it.
USING PHP
Using PHP
With PHP, its 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.
<?php
echo " Today is " . date("l") . ". ";
?>
Here's the latest news.
Using PHP
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 servers system time.
Using PHP
The final output of the two parts looks like
this:
Today is Wednesday. Here's the
latest news.
Using MySQL
Of course, theres not much point to being able to change
HTML output dynamically 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 wasnt
correctly locked against corruption from multiple
simultaneous accesses.
Also, a flat file can get only so big before it becomes
unwieldy to managenot to mention the difficulty of
trying to merge files and perform complex searches in any
kind of reasonable time.
Using MySQL
Thats 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.
Using MySQL
The highest level of MySQL structure is a
database, within which you can have one or
more tables that contain your data.
For example, lets 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.
Using MySQL
One command that you might use to do this
is:
INSERT INTO users VALUES('Smith',
'John', 'jsmith@mysite.com');
PHP + MySQL
Using PHP, you can make all calls directly to
MySQL without having to run the MySQL
program yourself or use its command-line
interface.
This means you can save the results in arrays
for processing and perform multiple lookups,
each dependent on the results returned from
earlier ones, to drill right down to the item of
data you need.