Low cost ecommerce web development India flash website design

Introducing PHP

As we've discussed previously, PHP is a server-side scripting language. This concept

is not obvious, especially if you're used to designing pages with just HTML and

JavaScript. A server-side scripting language is similar to JavaScript in many ways,

as they both allow you to embed little programs (scripts) into the HTML of a

Web page. When executed, such scripts allow you to control what will actually

appear in the browser window with more flexibility than is possible using straight

HTML.

The key difference between JavaScript and PHP is simple. JavaScript is interpreted

by the Web browser once the Web page that contains the script has been

downloaded. Meanwhile, server-side scripting languages like PHP are interpreted

by the Web server before the page is even sent to the browser. And, once it's interpreted,

the results of the script replace the PHP code in the Web page itself,

so all the browser sees is a standard HTML file. The script is processed entirely

by the server, hence the designation: server-side scripting language.

Let's look back at the today.php example presented in Chapter 1:

<html>

<head>

<title>Today's Date</title>

</head>

<body>

<p>Today's Date (according to this Web server) is

<?php

echo( date("l, F dS Y.") );

?></p>

</body>

</html>

Most of this is plain HTML. The line between <?php and ?>, however, is written

in PHP. <?php means "begin PHP code", and ?> means "end PHP code". The

Web server is asked to interpret everything between these two delimiters, and

to convert it to regular HTML code before it sends the Web page to the requesting

browser. The browser is presented with something like this:

<html>

<head>

<title>Today's Date</title>

</head>

<body>

<p>Today's Date (according to this Web server) is

Wednesday, May 30th 2001.</p>

</body>

</html>

Notice that all signs of the PHP code have disappeared. In its place, the output

of the script has appeared, and looks just like standard HTML. This example

demonstrates several advantages of server-side scripting:

. No browser compatibility issues. PHP scripts are interpreted by the Web

server and nothing else, so you don't have to worry about whether the language

you're using will be supported by your visitors' browsers.

. Access to server-side resources. In the above example, we placed the date

according to the Web server into the Web page. If we had inserted the date

using JavaScript, we would only be able to display the date according to the

computer on which the Web browser was running. Now, while this isn't an

especially impressive example of the exploitation of server-side resources, we

50

Getting Started with PHP

could just as easily have inserted some other information that would be

available only to a script running on the Web server. An example might be

information stored in a MySQL database that runs on the Web server computer.

. Reduced load on the client. JavaScript can slow significantly the display of

a Web page on slower computers, as the browser must run the script before

it can display the Web page. With server-side scripting, this burden is passed

to the Web server machine.

website designer freelance ASP PHP ecommerce web developer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110