Using PHP for Web applications

Jun 14, 2009 Author: Developer

In the beginning, Web pages were static — they just presented documents.
Users went to Web sites to read information. Documents were linked together
so that users could easily find the information they sought, but the Web pages
didn’t change. Every user who arrived at a Web page saw the same thing.

Soon Web page developers wanted to do more. They wanted to interact with
visitors, collect information from users, and provide Web pages that were
customized for individuals. Several languages have developed that can be
used to make Web sites dynamic. PHP is one of the most successful of these
languages, evolving quickly to become more and more useful and rapidly
growing in popularity.
PHP is a server-side scripting language, which means that the scripts are executed
on the server (the computer where the Web site is located). This is different
than JavaScript, another popular language for dynamic Web sites. JavaScript
is executed by the browser, on the user’s computer. Thus, JavaScript is a clientside
language. Web servers and the interaction between servers and clients are
discussed in the section “PHP for the Web,” later in this chapter.
Because PHP scripts execute on the server, PHP can dynamically create the
HTML code that generates the Web page, which allows individual users to
see customized Web pages. Web page visitors see the output from scripts,
but not the scripts themselves.
PHP has many features designed specifically for use in Web sites, including
the following:

  •  Interact with HTML forms: PHP can display an HTML form and process

the information that the user types in.

  •  Communicate with databases: PHP can interact with databases to store

information from the user or retrieve information that is displayed to
the user.

  •  Generate secure Web pages: PHP allows the developer to create secure

Web pages that require users to enter a valid username and password
before seeing the Web page content.
PHP features make these and many other Web page tasks easy.
PHP is only server-side, meaning it can’t interact directly with the user’s computer.
That means PHP can’t initiate actions based on the status of the user’s
computer, such as mouse actions or screen size. Therefore, PHP alone can’t
produce some popular effects, such as navigation menus that drop down or
change color. On the other hand, JavaScript, a client-side scripting language,

can’t access the server, limiting its possibilities. For example, you can’t use
JavaScript to store data on the server or retrieve data from the server. But
wait! You don’t have to choose. You can use JavaScript and PHP together to
produce Web pages that neither can produce alone. See Chapter 11 for details
on using JavaScript and PHP together.

views 3692
  1. Add New Comment