Use PHP to enhance UNIX/LINUX website functions _ PHP

Source: Internet
Author: User
Tags php3 file variable scope
The powerful functions of dynamic websites have been widely used soon. However, due to the well-known reasons, ASP can only be used in Microsoft's own operating system and server system. At present, the UNIX-based network system still occupies the majority, while the LINUX operating system is very popular due to its free provision and open source code, and its market share rapidly increases, it is said that the powerful functions of dynamic websites have been widely used soon. However, ASP can only be used
Microsoft's own operating system and server system. At present, UNIX-based network systems still occupy the majority, while LINUX
As the system is provided free of charge and open source code is very popular, its market share has rapidly increased, and it is said that it has reached about 17%;
APACHE servers are always the mainstream server software for network sites. The emergence and gradual improvement of PHP
For network developers of UNIX/LINUX systems, it is undoubtedly good news: we don't have to envy ASP any more.
It's easy to use, but unfortunately the complexity of PERL/C!

I. PHP features
PHP is called Personal Home Page. it was released and used in 1995 and has become a mature software platform by 1998.
Product. The latest version is 4.0, and the commonly used version is 3.0. PHP is compiled in C language and can run on
UNIX/LINUX and WIN9X/NT.
PHP is a cross-platform server-side embedded script technology. A php page is a text file,
Embedded PHP script statements in common HTML page files, which are interpreted and translated by the server into common HTML files.
And then transmitted to the client browser, which is the same as ASP.
PHP borrowed a lot of C, JAVA, and PERL syntax, and added a variety of PHP
Allows WEB developers to write dynamic pages quickly.
The PHP script uses "Is the end. " ".
The statement is replaced by a common HTML script after the server software calls the PHP script interpretation engine.
The author believes that the strongest and most representative feature of PHP lies in its database layer, which is built on many
Database support, without the need for special extensions, makes it very easy to write database-based web pages. Currently supported databases
Oracle, Adabas D, Sybase, FilePro, mSQL, Velocis, MySQL, Informix, Solid, dBase,
ODBC, Unix, dbm, PostgreSQL, and ms SQL SERVER. Each database has a set of functions for database access and operation.
For example, dbase_create, dbase_open, dbase_close, dbase_pack, dbase_add_record,
Dbase_delete_record, dbase_get_record, dbase_numfields, dbase_numrecords, and other functions. for MySQL
Mysql_close, mysql_connect, mysql_create_db, mysql_data_seek, mysql_dbname, mysql_db_query
And other functions.
PHP also provides a set of image functions to dynamically generate gif image data streams and output them
Client.
In addition, PHP also provides Socket, EMail, PDF file, HIS (Hyperwave Information
Server), IMAP, LDAP (Lightweight Directory Access Protocol), file upload, NIS, and other functions.


2. build a PHP application system platform
PHP can run on UNIX/LINUX + APACHE server system, WIN9X + PWS server system, or WINNT + IIS server system.
The following uses PWIN98 + PWS4.0 as an example to build a PHP learning and development environment.
(1) Download PHP3 For WIN9X/NT
To the http://www.php.net, select downloads, and then select Download the PHP source code and Windows
Distribution: Select a download site and select 3.0.11 Win32 binary. If you are in trouble
Use http://www.php.net/distributions/php-3.0.11-win32.zipit. The downloaded file is named php-3.0.11-win32.zip,
The size is 1.68 MB.
(2) install PHP3 For WIN9X/NT
Installing PHP3 For WIN9X/NTIS simple. you only need to extract php-3.0.11-win32.zip to a directory. In the following
In the discussion, we assume that PHP3 is installed in the C: \ Program Files \ PHP3 directory.
(3) configure PHP3 For WIN9X/NT
To configure PHP3 For WIN9X/NT, you must modify the system settings so that PWS4.0 can use the PHP3 script engine to explain the PHP page.
1. copy the file php3-dist.ini in the C: \ Program Files \ PHP3 directory to the Windows 98 installation directory (such as C: \ PWIN98)
And change it to php3.ini.
2. edit the php3.ini file
Edit the php3.ini file and change the "Extension_dir" under "Paths and Directories" to "Extension_dir ".
= C: \ Program Files \ PHP3; change "browscap" under "browscap" to "browscap = C: \ PWIN98 \ SYSTEMinetsrv \ browscap. ini "(PWS4.0 installation directory file); add a string value under the primary key of HKEY_LOCAL_MACHINE \ SystemCurrentControlSet \ Services \ W3Svc \ Parameters \ ScriptMap in the registry, whose name is
". Php3" (the PHP3 file extension) with the value "C: \ Program Files \ PHP3 \ php.exe % s ".
In this way, after the PWS server software is restarted, PWS4.0 can use the PHP3 script engine to explain the PHP page.

Introduction to PHP script syntax
In the PHP3 file, "For the end, use" "
Is the PHP program segment.
The PHP syntax is similar to the C and Perl syntax and mainly comes from the C language. for example, the control flow statement is almost identical to the C syntax, and
Operators are similar to C, function definitions, and calls are similar to C.
The variable name in PHP must have a $ sign before it, such as $ Var1 and $ Var2. The variable scope of PHP is also similar to C, that is, the main function is considered by default.
The variable in the number is a global variable, and the variable in the function is a local variable.
In PHP, the echo and printf functions are used to output HTML content to HTML pages. echo outputs a non-formatted string, while printf outputs
Returns the formatted string. For example, echo ("
This PHP page ") and printf (" % s, % d ", str1, int1 ).
If you are familiar with the C language syntax, it is not difficult to learn the PHP script syntax.

4. create your own simple PHP page
The so-called PHP page is to insert some special scripting languages in common HTML page files and save them with the extension PHP
Therefore, you can easily create a simple PHP page.
The following is a simple PHP page File (test01.php3), which should not be hard to understand.



A simple PHP3 page




The following four lines of statements should appear, with the font size ranging from 4 to 7


> The font size of this line of statements is




Where, the statement Is to output the variable I value to the HTML file.
As shown in the preceding figure, you can create a common HTML page file and insert the PHP script language as needed.
The key is to be familiar with PHP script statements.
Although this page is simple, it can help you familiarize yourself with and understand the PHP syntax. you can use a browser to view the running effect and use it to view the source code.
For more information about the code function, see the HTML file after the PHP page is interpreted. Note that you must use http to access the PHP page,
You cannot double-click a file name as an HTML page file to browse the file.
Http: // wangfajun/test01.php3, because the PHP page needs to be explained by server software such as PWS.

4. obtain user request information
To create a dynamic website page, it is essential to obtain user request information. PHP pages can use this information as some applications.
(Such as commercial order information) basis, and feedback on the applicant's application requirements.
On the ASP page, you can use its built-in object Request to obtain the visitor's application information. On the PHP page, you can read
Array to obtain the application information of a visitor, such as Form Field and QueryString. Request page
The request information sent in POST mode can be obtained in the form of $ HTTP_POST_VARS ["ItemName "].
The request information can be obtained in the form of $ HTTP_GET_VARS ["ItemName"], and the cookie information can be obtained in the form of $ HTTP_COOKIE_VARS [
"ItemName. Generally, the form information is sent as POST, which can be in the format of $ HTTP_POST_VARS ["ItemName "]
The query information is sent in GET mode and can be obtained in $ HTTP_GET_VARS ["ItemName"] mode.
(1) one HTML or PHP3 page requests another PHP3 page for processing
In the following example, the applicant is required to fill in the full name, ID number,
EMail address. Notify the reader of successful registration after receiving the application.
Create an application page for reader membership registration, which can be an HTML page or a PHP page. This should not be a problem.



Reader membership registration application


Reader membership registration application




On the application page, all the application data is filled in the Form element, and the processing is specified in the Form Action.
The application page is test02.php3. When receiving the application, the data of the corresponding project can be changed from $ HTTP_POST_VARS ["project name"]
"Project name" is the name of the Form element, for example, "full name" corresponds to "FullName", for example, "ID card number"
It should be "UniversalID ". Now we can use this information to create a successfully registered notification page test02.php3.



Reader qualification registration application successful


Reader qualification registration application successful

Dear Readers:

We have received your application and accepted your application. you have become an official reader member of our department.

Your reader number is CN . We will use your email box
To officially inform you. Since then, we will hold a reader salon event
And the location will also be notified to you through this mailbox.


Open the application page apply.htm with a browser, enter the corresponding data, submit the application, view the feedback, and then use the browser.
To view the source code, you can see the HTML file after the PHP page interpretation.

(2) a PHP3 page requests the same PHP3 page for processing
In another example below, login. php3 provides a user logon page that requires the user to enter the logon account and password,
Then, use the Form Action attribute to send the table to the user for processing. In login. php3, the table will be sent based on the account and password.
Whether it is blank to determine whether to enter the page or feedback page, and give different prompts. If no account or password is entered, the system prompts "user
Log on, enter the user account and password. Otherwise, the user account and password are displayed.



User logon


If (Empty ($ HTTP_POST_VARS ["mermerid"]) then modify
Empty ($ HTTP_POST_VARS ["Password"])
{
?>

Log on as a user. enter your account and password.



}
Else file: // If you have entered your account and password, the user account and password are displayed.
{
Printf ("

User % s login successful, password % s.

", $ HTTP_POST_VARS [" CustomerID "],
$ HTTP_POST_VARS ["Password"]);
}
?>



(3) obtain query parameter information on the PHP3 page
When the user uses xxxxx. php3? When sending a query request in ParaName = ParaValue mode, xxxxx. php3 can
Obtain the ParaName information submitted by the user from $ HTTP_GET_VARS ["ParaName"]. you can also
Obtain the number of user request parameters from count ($ HTTP_GET_VARS) and process them accordingly.
When the user uses query. php3? When a query request is sent using CustomerID = 7777, query. php3 can
The value of CustomerID in $ HTTP_GET_VARS ["CustomerID"] to obtain the query parameter is 7777,
Count ($ HTTP_GET_VARS) is 1.
When the user uses query. php3? When a query request is sent using CustomerID = 7777 & Password = DogIsDog
, Query. php3 can obtain the CustomerID value of the query parameter from $ HTTP_GET_VARS ["CustomerID "].
7777. obtain the value of the query parameter Password from $ HTTP_GET_VARS ["Password"] as DogIsDog,
Count ($ HTTP_GET_VARS) is 2.
The following example (query. php3) is used to obtain the query parameters specified by the user and display them to the user. When
Query. php3? When you send a request in CustomerID = 1111 & StartDate = & EndDate =,
The result is as follows:
You have specified three query parameters as follows:
The value of CustomerID is 1st.
The value of StartDate is 2nd.
The value of the EndDate parameter 3rd is:



Query parameter processing


$ QueryCount = count ($ HTTP_GET_VARS); // query the number of parameters
Printf ("

You have specified % d query parameters as follows: ", $ QueryCount); // displays the number of query parameters.
File: // lists the query parameters and their values.
For ($ intIndex = 0; list ($ key, $ val) = each ($ HTTP_GET_VARS); $ intIndex ++)
{
Printf ("

The value of the % d parameter % s is: % s ", $ intIndex + 1, $ key, $ val );
}
?>



(4) obtain users' Cookies
Cookies can be transmitted between the server and the client. they record certain information of a specific user.
You can use $ HTTP_COOKIE_VARS ["CookieItemName"] to obtain your Cookies. The following statement can be used to display
Show all Cookies of a user:
$ QueryCount = count ($ HTTP_COOKIE_VARS); // number of cookies
Printf ("

You have % d Cookies as follows: ", $ QueryCount); // display the number of Cookies
File: // list each Cookie and its value
For ($ intIndex = 0; list ($ key, $ val) = each ($ HTTP_COOKIE_VARS); $ intIndex ++)
{
Printf ("

The value of Cookie (% s) for article % d is: % s ", $ intIndex + 1, $ key, $ val );
}
?>

(5) obtain server environment information
In PHP, server environment information is given in the form of a group of global variables for PHP script programs to access.
Common server environment variables include:
$ GATEWAY_INTERFA
CE: Gateway interface, such as CGI/1.1
$ HTTP_ACCEPT: List of MIME types acceptable to the client, for example */*
$ HTTP_ACCEPT_LANGUAGE: the language used by the server. "en" indicates English and "zh-cn" indicates simplified Chinese.
$ HTTP_HOST: HTTP server name
$ HTTP_USER_AGENT: the client browser type that sends the request. it is identified based on the user request information and browscap. ini,
For example, Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
$ LOCAL_ADDR: name of the local server
$ PATH_TRANSLATED: The full name (including the actual path) of the script file, as shown in
C: \ Inetpub \ wwwroot \ php3 \ query. php3
$ REMOTE_ADDR: IP address of the client machine sending the request
$ REMOTE_HOST: name of the client machine sending the request
$ REQUEST_METHOD: Method for sending a request (Post/Get/Head)
$ SCRIPT_NAME: the path and name of the called script file, for example,/php3/query. php3
$ SERVER_NAME: server name or IP address
$ SERVER_PORT: HTTP service port number, which is generally 80.
$ HTTP_REFERER: The URL of the page on which the client sends a CGI program request
$ SERVER_PROTOCOL: the protocol used by the server software, for example, HTTP/1.1.
$ SERVER_SOFTWARE: name and version of the server software, for example, Microsoft-IIS/4.0

5. send messages to users
You can use the functions provided by PHP to flexibly control the content and methods of information sent to the client. for example, you can dynamically set feedback.
Information, set the customer's Cookie, page location, and so on.
(1) use PHP functions such as echo and printf to control the sent information.
The echo and printf functions can directly output content to HTML files sent to the client browser.
In the following example, selecolr. php3 requires the user to enter a color name. after the user confirms, send the application
Go to selecolr. php3 on the same page and display the color name in the specified color.



Mixed programming of server scripts and client scripts


When you move the cursor over the project name on each record, pay attention to the changes in the status bar content.








Project name Status bar content

The mouse is now pointing to the project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.