Anything 2 Share All - Tips Make money online-Phim-video clip-wallpage-software-picture!

Share for all tip, tut, free picture, film, video clip, wallpage, software, etc...

Core PHP Programming - Part II: Functional Reference

Chapter 8. Browser I/O
Topics in This Chapter
If you are experienced in traditional application development, you may be challenged by the unique characteristics of a stateless operating environment. Your script can't sit in a loop and get input from the user until the quit button is clicked. Although there are ways to force the preservation of state—that is, a collection of variables for each user—I encourage you to work within PHP's world. You may come to find what at first were limitations are refreshing opportunities.
8.1 Pregenerated Variables
Before executing a script, PHP creates a set of variables available in a superglobal namespace. They are available inside functions and classes without any extra declaration.

_COOKIE
The _COOKIE variable is an array of cookies sent from the browser to the server. The keys in the array are names of cookies.

_ENV
The _ENV variable is an array of environment variables that existed when the script began. The keys in the array are the names of the environment variables.

_FILES
The _FILES array (Table 8.1) contains information about uploaded files. The keys to the array are the names of the form variables. Each value is an array of information about each file. See Chapter 7 for a discussion of file uploads.
Table 8.1. Elements of _FILES Array
Element
Description
error
The error message, if any, associated with the uploaded file.
name
The name of the uploaded file as supplied by the uploading browser.
size
The size in bytes of the uploaded file.
tmp_name
The path in the local file system to the uploaded file.
type
The MIME type of the uploaded file, provided by the browser.

_GET
The _GET array contains values for all fields passed using the GET method. Keys in this array are the names of the variables passed in the request.

GLOBALS
The GLOBALS array contains every variable in the global scope.

php_errormsg
This variable holds a string describing the last error if track_errors is turned on. It's overwritten with each error.

_POST
The _POST array contains values for all fields passed using the POST method. Keys in this array are the names of the variables passed in the request.

_REQUEST
The _REQUEST array combines the contents of _GET, _POST, _COOKIES, and _FILES. In the case of variables with identical names, PHP overwrites entries according to the variables_order directive in php.ini.

_SERVER
The _SERVER array contains information describing the server and its environment. The following list of elements may appear in the _SERVER array, depending on the Web server or if the script is run from a shell.

argc
If run from the command line, PHP will place an integer in this variable representing the number of arguments passed.

argv
If run from the command line, PHP will set this variable with an array. Each element of the array represents one argument passed. When running within a Web server, PHP places the query string in this variable.

DOCUMENT_ROOT
This value contains the path to document root. A typical value for Apache is /usr/local/apache/htdocs.

GATEWAY_INTERFACE
This value describes the version of the Common Gateway Interface (CGI) used by the Web server.

HTTP_ACCEPT
This value mirrors the Accept header sent by the Web server. It is a comma-delimited list of MIME types.

HTTP_ACCEPT_CHARSET
This value mirrors the Accept-Charset header sent by the Web server.

HTTP_ACCEPT_ENCODING
This value mirrors the Accept-Encoding header sent by the Web server.

HTTP_ACCEPT_LANGUAGE
This value mirrors the Accept-Language header sent by the Web server.

HTTP_CONNECTION
This value mirrors the Connection header sent by the Web server.

HTTP_HOST
This value mirrors the Host header sent by the Web server.

HTTP_REFERER
This value mirrors the Referer header sent by the browser.

HTTP_USER_AGENT
This value mirrors the User-Agent header sent by the browser.

PATH_TRANSLATED
This value is the path to the requested PHP script.

PHP_AUTH_PW
This value is the password sent by the browser.

PHP_AUTH_TYPE
This value describes the authentication type.

PHP_AUTH_USER
This value is the user name sent by the browser.

PHP_SELF
This value is the path to the requested script relative to the document root.

QUERY_STRING
This value is the complete query string.

REMOTE_ADDR
This value is the IP address of the browser.

REMOTE_PORT
This value is the port on the browser's machine used for receiving data from the server.

REQUEST_METHOD
This value describes the method used in the request by the browser. It may contain GET, HEAD, POST, or PUT.

REQUEST_URI
This value is the Universal Resource Identifier (URI) requested by the browser. Of the information that appears in a browser's location box, it excludes only the transport protocol and server name.

SCRIPT_FILENAME
This value is the path in the server's local filesystem to the requested script.

SCRIPT_NAME
This value is the external path to the requested script.

SERVER_ADMIN
This value is the email address of the Web server's administrator.

SERVER_NAME
This value is the domain name of the server.

SERVER_PORT
This value is the port on which the server listens for requests.

SERVER_PROTOCOL
This value contains a description of the version of HTTP used by the server.

SERVER_SIGNATURE

Core PHP Programming - Part I: Programming with PHP!

The first part of this book is a thorough discussion of PHP as a programming language. You will be introduced to common concepts of computer science and how they are implemented in PHP. No prior programming experience beyond the use of simple mark-up languages is necessary. That is, you must be familiar with HTML. These chapters focus on building a foundation of understanding rather than on how to solve specific problems. If you have experience programming in a similar language, such as C or Perl, you may choose to read Chapter 1 and skim the rest, saving it as a reference. In most situations, PHP treats syntax much as these two languages do.
Chapter 1 is an introduction to PHP—how it began and what it looks like. It may be sufficient for experienced programmers, since it moves quickly through PHP's key features. If you are less experienced, I encourage you to treat this chapter as a first look. Don't worry too much about exactly how the examples work. I explain the concepts in depth in later chapters.
Chapter 2 introduces the concepts of variables, operators, and expressions. These are the building blocks of a PHP script. Essentially, a computer stores and manipulates data. Variables let you name values; operators and expressions let you manipulate them.
Chapter 3 examines the ways PHP allows you to control program execution. This includes conditional branches and loops.
Chapter 4 deals with functions, how they are called and how to define them. Functions are packages of code that you can call upon repeatedly.
Chapter 5 is about arrays—collections of values that are identified by either numbers or names. Arrays are a very powerful way to store information and retrieve it efficiently.
Chapter 6 is about classes, presenting an object-oriented approach to grouping functions and data. Although not strictly an object-oriented language, PHP supports many features found in OO languages such as Java.
Chapter 7 deals with how PHP sends and receives data. Files, network connections, and other means of communication are covered.

1.1 The Origins of PHP

Wonderful things come from singular inspiration. PHP began life as a simple way to track visitors to Rasmus Lerdorf's resume. It also could embed SQL queries in Web pages. But as often happens on the Web, admirers quickly asked for their own copies. As a proponent of the Internet's ethic of sharing, and as a generally agreeable person, Rasmus unleashed upon an unsuspecting Web his Personal Home Page Tools version 1.0.
"Unleashed upon himself" may be more accurate. PHP became very popular. A consequence was a flood of suggestions. PHP 1.0 filtered input, replacing simple commands for HTML. As its popularity grew, people wondered if it couldn't do more. Loops, conditionals, rich data structures—all the conveniences of modern structured programming seemed like a next logical step. Rasmus studied language parsers, read about YACC and GNU Bison, and created PHP 2, otherwise known as PHP/FI.
PHP/FI allowed developers to embed structured code inside HTML tags. PHP scripts could parse data submitted by HTML forms, communicate with databases, and make complex calculations on the fly. And it was very fast because the freely available source code compiled into the Apache Web server. A PHP script executed as part of the Web server process and required no forking, often a criticism of Common Gateway Interface (CGI) scripts.
PHP was a legitimate development solution and began to be used for commercial Web sites. In 1996, Clear Ink created the SuperCuts site (www.supercuts.com) and used PHP to create a custom experience for the Web surfer. The PHP Web site tracks the popularity of PHP by measuring how many different Web sites use the PHP module. When writing the second edition of this text, it seemed really exciting that PHP had grown from 100,000 sites to 350,000 sites during 1999. The most recent data show more than 10 million domains using PHP!
In 1997, a pair of Israeli students named Andi Gutmans and Zeev Suraski attempted to use it for building an online shopping cart, considered cutting-edge enough to be a university project. Shortly after they started, they stumbled upon various bugs in PHP that made them look under the hood at the source code. To their surprise, they noticed that PHP's implementation broke most of the principles of language design, which made it prone to unexpected behavior and bugs. Always looking for good excuses not to study for exams, they started creating a new implementation. In part, the task was a test of their programming abilities, in part a recreation. A few months later, they had rewritten PHP from scratch, making it a real, consistent, and robust language for the first time. Having spent so much time on the project, they asked the course teacher, Dr. Michael Rodeh, for academic credit in an attempt to avoid unnecessary exams. Being the manager of the IBM Research Lab in Haifa and well aware of the overwhelming number of different languages to choose from, he agreed—with the stipulation that they cooperate with the existing developers of PHP/FI instead of starting their own language.
When Andi and Zeev emailed Rasmus with the news about their rewrite, they wondered if he would accept this new work, as it essentially meant discarding his implementation. Rasmus did accept it, and a new body was formed—the PHP Core Team, known today as the PHP Group. Along with Andi, Rasmus, and Zeev, three other developers—Stig Bakken, Shane Caraveo, and Jim Winstead—were accepted to the Core Team. A community of developers started growing around PHP.
After seven months of development, alpha and beta testing, PHP version 3.0 was officially released on June 6, 1998, and started bending the curve of PHP's growth to unprecedented angles. PHP's functionality was growing on a daily basis, and PHP applications were popping up everywhere. Following the release, Open Source projects written in PHP flourished. Projects like Phorum tackled long-time Internet tasks such as hosting online discussion. The PHPLib project provided a framework for handling user sessions that inspired new code in PHP. FreeTrade, a project I led, offered a toolkit for building e-commerce sites.
Writing about PHP increased as well. More than 20 articles appeared on high-traffic sites such as webmonkey.com and techweb.com. Sites dedicated to supporting PHP developers were launched. The first two books about PHP were published in May 1999. Egon Schmid, Christian Cartus, and Richard Blume wrote a book in German called PHP: Dynamische Webauftritte professionell realisieren. Prentice Hall published the first edition of my book, Core PHP Programming. Since then, countless books about PHP fill bookstore shelves.
Given this background, there were no reasons not to be happy with the way PHP was back then. Perhaps the internal knowledge of what was going on under the hood and the feeling familiar to every developer—"I could have done it much better"—were the reasons that Andi and Zeev were some of the very few people who felt unhappy with PHP 3. As if out of habit, they withdrew from the PHP community and attempted to design a new approach towards executing PHP scripts.
A few months later, on January 4, 1999, Zeev and Andi announced a new framework that promised to increase dramatically the performance of PHP scripts. They dubbed the new framework the Zend Engine. Early tests showed script execution times dropping by a factor of 100. In addition, new features for compiling scripts into binary, debugging, optimization, and profiling were planned. This announcement officially ended the PHP 3.1 project, which was supposed to bring better Windows support to PHP 3 but failed to gain momentum, and officially started the planning of PHP 4.
Work on the Zend Engine and PHP 4 continued in parallel with bug fixes and enhancements to PHP 3. During 1999, eight incremental versions were released, and on December 29, 1999, PHP version 3.0.13 was announced. A PHP beta based on the Zend Engine became publicly available in July 19, 1999, and was followed by an intense development period of various components, some of which were brand new, such as built-in session handling, output buffering, and a Web server abstraction layer. The release of PHP 4 on May 22, 2000, marked another important milestone on PHP's journey to becoming the most popular Web development platform on earth. The number of people working on various levels of PHP has grown immensely, and new projects, most notably PEAR, gained momentum and started pushing PHP to new heights of popularity.
The PHP community drives the development of new features. Many programmers find inspiration in object-oriented programming. PHP 3 introduced objects as syntactic sugar. That is, while the syntax used for objects was different, the underlying implementation varied little from arrays. It attracted many object-oriented advocates, but the limited implementation left them desiring more. PHP 5 addresses these needs with a strong, rebuilt object system.

Donation

Search By Your Customize

Custom Search

Subscription

Enter your email address:

Delivered by FeedBurner

Labels

Sponsored Links

Asd by any program
Free Website Hosting affiliate_link adf.ly - shorten links and earn money!