Section 8.0. Introduction


8.0. Introduction

Web programming is probably why you're reading this book. It's why the first version of PHP was written and what continues to make it so popular today. With PHP, it's easy to write dynamic web programs that do almost anything. Other chapters cover various PHP capabilities, like graphics, regular expressions, database access, and file I/O. These capabilities are all part of web programming, but this chapter focuses on some web-specific concepts and organizational topics that will make your web programming stronger.

Recipes 8.1, 8.2, and 8.3 show how to set, read, and delete cookies. A cookie is a small text string that the server instructs the browser to send along with requests the browser makes. Normally, HTTP requests aren't "stateful"; each request can't be connected to a previous one. A cookie, however, can link different requests by the same user. This makes it easier to build features such as shopping carts or to keep track of a user's search history.

Recipe 8.4 shows how to redirect users to a different web page than the one they requested. Discovering the features of a user's browser is shown in Recipe 8.5. Recipe 8.13 shows the details of constructing a URL that includes a get query string, including proper encoding of special characters and handling of HTML entities. Similarly, Recipe 8.7 provides information on reading the data submitted in the body of a post request. Recipe 8.8 discusses a common web formatting need: displaying rows of an HTML table such that alternating rows have different colors or styles.

The next three recipes demonstrate how to use authentication, which lets you protect your web pages with passwords. PHP's special features for dealing with HTTP Basic authentication are explained in Recipe 8.9. Sometimes it's a better idea to roll your own authentication method using cookies, as shown in Recipe 8.10.

The three following recipes deal with output control. Recipe 8.11 shows how to force output to be sent to the browser. Recipe 8.12 explains the output buffering functions. Output buffers enable you to capture output that would otherwise be printed or delay output until an entire page is processed. Automatic compression of output is shown in Recipe 8.13.

The next two recipes show how to interact with external variables: environment variables and PHP configuration settings. Recipes 8.14 and 8.15 discuss environment variables. If Apache is your web server, you can use the techniques in Recipe 8.16 to communicate with other Apache modules from within your PHP programs.

This chapter also includes two programs that demonstrate some of the concepts in the recipes. Recipe 8.17 validates user accounts by sending an email message with a customized link to each new user. If the user doesn't visit the link within a week of receiving the message, the account is deleted. Recipe 8.18 is a small example of a Wiki'a system that makes any page on your web site editable from within the web browser.




PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon

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