All advanced PHP skills released_PHP tutorial

WBOY
Release: 2016-07-20 11:05:46
Original
854 people have browsed it

More than 3 million Internet website administrators around the world are using PHP, making it one of the most popular server-side scripting languages. It is characterized by fast running speed, stability, reliability, cross-platform, and open source software. Depending on your level of use, PHP can be as simple as it can be as complex, and you can use it just to send HTML table elements, or you can integrate Java and XML into your PHP application.
If you have a certain understanding of PHP or have read some preliminary textbooks, these techniques can expand your familiarity with PHP and enable you to master some common and advanced PHP functions.
1. Install PHP as Apache's DSO
PHP is often used with Apache on Linux/Unix platforms. When installing PHP, there are three installation methods to choose from: static mode, dynamic mode (DSO), CGI binary mode.
Due to ease of maintenance and upgrades, I highly recommend installing PHP in DSO mode. For example, if the installed PHP only supports databases during the initial installation, and then you want to install modules that support encryption, you only need to run "make clean", add new configuration options, and then run "make" and "make install". The new PHP module will be installed in the appropriate location in Apache, and Apache will be restarted without recompiling Apache.
The following steps will install a new Apache and install PHP in DSO mode:
1. Obtain the latest version of Apache source code from the Apache Software Foundation;
2. Put the obtained source code in /usr/local/ or /opt/ directory, or any directory you specify;
3. Run Gunzip to decompress the file and get a file with the suffix .tar;
4. Run the following command , install the file into the apache_[version] directory:
tar -xvf apache_[version].tar
5. Enter the /usr/local/apache_[version] directory (or install the compressed file in step 4 Directory);
6. Type the following command to prepare for compiling Apache, replace [path] with your own path, for example, /usr/local/apache[version], now the new value of mod_so has been set , it will allow Apache to use the DSO module;
7. Type make after returning to the prompt state, and wait to return to the prompt state again;
8. Execute the "make install" command.
At this point, Apache has been installed and the system will return to the prompt state. Next we start installing PHP:
1. Find the link to the latest version in the download area of ​​the PHP homepage;
2. Download the file to an appropriate directory, such as /usr/local/ or /opt/ Or in any directory you specify;
3. Run Gunzip to decompress the file and get a file with the suffix .tar;
4. Execute the following command to install the file in the php-[version] directory:
tar -xvf php-[version]
5. Enter the /usr/local/php-[version] directory or the directory specified in step 4;
At this point, the installation in DSO mode has been completed For PHP preparatory work, the only configuration option that needs to be modified is with-apxs (this is a file in Apache's bin directory). In order to get higher performance, I did not install the support module for MySQL.
./configure --with-mysql=/[path to mysql] --with-apxs=/[path to apxs]
6. Execute the make command after returning to the prompt state, and wait to return to the prompt. symbol status;
7. Execute the make install command.
At this point, the system has installed PHP in Apache’s module directory in DSO mode, made appropriate modifications to Apache’s httpd.conf file, and returned to the prompt state. After returning to the prompt state, you still need to make some modifications to Apache's httpd.conf file.
1. Find the line that contains ServerAdmin and add your email address as follows:
ServerAdmin you@yourdomain.com
2. Find the line that starts with ServerName and change it to the real one Value, for example:
ServerName localhost
3. Find the section with the following content:
# And for PHP 4.x, use:
#
#AddType application/x-httpd- php .php
#AddType application/x-httpd-php-source .phps
Modify the contents of these lines so that AddType of PHP 4.0 is no longer a comment, and add the file suffix you want to use in PHP, The above content changes to the following content:
# And for PHP 4.x, use:
#
AddType application/x-httpd-php .php .phtml
AddType application/x -httpd-php-source .phps
Save the file, return to the previous directory, and execute the following command to restart Apache:
./bin/apachectl start
If no error message appears during startup , you can test the installed Apache and PHP by creating a file named phpinfo.php with only one line as shown below:

Save this file to Apache's document root directory (htdocs), then open the browser and type the http://localhost/phpinfo.php address, and many variables and their values ​​will appear on the screen.
If you want to reconfigure PHP, you need to run the make clean command again, then execute the ./configure command with a series of options, and then execute the make and make install commands. A new module will appear in the Apache directory module. Just restart Apache to load this new module and everything will be OK.
2. Dialogue using PHP itself
The most anticipated feature of PHP 4.0 should be support for conversations. Users of PHP 3.0 must use third-party software or they cannot use conversations. Not supporting conversations has always been one of the biggest shortcomings of PHP.
You can use conversations to maintain variables relevant to a specific user as long as the user is browsing your site without having to create multiple cookies, use hidden table fields, or store information in a database.
Starting a session on a web page will let the PHP engine know that you want to start a session (if it is not already started) or continue the current session:
session_start();
Starting a session will pass the cookie An identification string is sent to the user (for example, 940f8b05a40d5119c030c9c7745aead9). On the server side, a temporary file matching the identification string is created, such as sess_940f8b05a40d5119c030c9c7745aead9. This file contains the registered conversation variables and their values.
The most common example used to show the role of a dialog is an access counter. Start the PHP module and make sure that the PHP code is the first line of the file. There should be no spaces, HTML codes, or other codes before the PHP code. Because the session sends a header, if there are spaces and HTML code before session_start(), you will get an error message.
// If there is no user for a certain user, start a conversation:
session_start();
Then register a variable named count:
session_register ('count');
After registering a dialogue variable, as long as the dialogue exists, the variable named count will also exist. Now, the count variable has not been assigned a value. If you add 1 to it, its value will become 1.
$count ;
Putting the above contents together, if a conversation has not been started, a conversation will be started; if there is no conversation id, just specify one for the user and register a name as $ Count variable, adding 1 to $count indicates that the user has visited the web page for the first time.


To know how many times the user has visited this page in the current conversation, simply display the value of the $count variable:
echo "

You've been here $count times .

";
The entire access counter code is as follows:
session_start();
session_register('count');
$count ;
echo "

You've been here $count times.

";
?>
If you reload the above script file, you will find that the value of the variable count has increased 1. It’s cool.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445096.htmlTechArticleMore than 3 million Internet website administrators around the world are using PHP, making it the most popular server-side script. One of the languages. It is characterized by fast running speed, stability and reliability, and cross-platform...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!