Workshop


The following workshop includes questions you might ask about server-side development, quizzes to test your knowledge, and two quick exercises.

Q&A

Q

At work, all of our applications are written using Active Server Pages. Why didn't you write about that?

A

There are a number of popular platforms for writing web applications. PHP has the advantage of running on a number of operating systems, including Windows, Mac OS X, and Linux. Furthermore, support for PHP is offered by many web hosting providers. Finally, as you'll learn in the next lesson, there are many applications already written in PHP that you can take advantage of. Knowledge of PHP can be helpful in working with them.

Q

Do I need a special application to edit PHP files?

A

Just as with HTML, PHP files are normal text documents. Some text editors have specialized features that make working with PHP easier, just as there are for HTML. If you're just starting out, using Notepad or any other regular text editor will work fine, but you'll probably want to find a more powerful tool for writing PHP if you find yourself programming in PHP a lot.

Q

How do I deploy PHP files to a server?

A

There are no special requirements for deploying PHP files. You can just transfer them to the server as you would regular HTML files. As long as the server is configured to handle PHP, you should be fine. The one thing you do need to be careful to do is to make sure your directory structure is the same on the server and on your local computer. If you are using includes and directory paths change, your includes will break.

Q

Are PHP scripts browser-dependent in any way?

A

All of the processing in PHP scripts takes place on the server. They can be used to produce HTML or JavaScript that won't work with your browser, but there's nothing in PHP that will prevent it from working with a browser.

Quiz

1.

What is the difference between double and single quotes in PHP?

2.

How do the include_once and require_once functions differ?

3.

Which functions can be used to help avoid cross-site scripting attacks?

4.

How do you declare an associative array in PHP?

Quiz Answers

1.

In PHP, strings in double quotes are parsed for variable references and special characters before they are presented. Strings in single quotes are presented as is.

2.

The include_once function does not return a fatal error if the file being included is not found. With require_once, if the file is not found, a fatal error occurs and the rest of the page is not processed.

3.

You can use htmlspecialchars() to escape the characters used to generate HTML tags for a page. You can use strip_tags() to remove any HTML tags from a string. Either approach should prevent users from using malicious input to attempt a cross-site scripting attack.

4.

Associative arrays are declared as follows:

$array = ('key' => 'value, 'key2' => 'value2');


Exercises

1.

Get PHP up and running on your own computer.

2.

Write a script that enables a user to show the current date and time on a web page.

3.

Go to the PHP manual online and find a built-in function that wasn't introduced in this lesson. Use it in a script of your own.




Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day
Sams Teach Yourself Web Publishing with HTML and CSS in One Hour a Day (5th Edition)
ISBN: 0672328860
EAN: 2147483647
Year: 2007
Pages: 305

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net