PHP Advanced Tips Full Broadcast _php tutorial

Source: Internet
Author: User
Tags phpinfo
With more than 3 million Internet sites worldwide, the administrator is using PHP, making it one of the most popular server-side scripting languages. It is characterized by fast running, stable and reliable, cross-platform, and open source software. Depending on the level you use, PHP can be very simple or complex, you can use it to send HTML table elements only, and you can integrate Java and XML into your PHP application.
If you have a good understanding of PHP or have read some preliminary textbooks, these techniques can expand your familiarity with PHP and allow you to grasp some common and advanced PHP features.
First, the installation of PHP as Apache DSO
PHP is often used with Apache on the Linux/unix platform, with three installation options available when installing PHP: static mode, dynamic mode (DSO), CGI binary mode.
Because it is easy to maintain and upgrade, I strongly recommend that you install PHP in DSO mode. For example, if the installed PHP only supports the database at initial installation, and then you want to install the module that supports encryption, just run "make clean", add new configuration options, and then run "make" and "Make install". A new PHP module will be installed in the appropriate location in Apache, and then re-launch Apache without recompiling Apache.
The following steps will install a completely new Apache and install it in the DSO mode:
1, from the Apache Software Foundation to get the latest version of the Apache source code;
2. Put the obtained source code into the/usr/local/or/opt/directory, or any directory you specify;
3. Run Gunzip to unzip the file and get the file suffix. tar;
4. Run the following command to install the file into the Apache_[version] directory:
TAR-XVF Apache_[version].tar
5. Enter the/usr/local/apache_[version] directory (or the directory where the compressed files are installed in step 4);
6. Type the following command to prepare for compiling Apache, replacing [path] with your own path, for example,/usr/local/apache[version], now set the new value of MOD_SO, which will promise Apache to use the DSO module;
7. After returning to the prompt state, type make and wait to return to the prompt again;
8. Execute the "make install" command.
Now that Apache is installed, the system will return to the prompt state. Next we start installing PHP:
1. Find the latest version of the link in the download area of the PHP homepage;
2. Download the file to an appropriate directory, such as/usr/local/or/opt/or any directory you specify;
3. Run Gunzip to unzip the file and get the file 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, has done the DSO installation of PHP preparation work, the only configuration options that need to be modified is WITH-APXS (this is a file in the Apache Bin directory). In order to get a higher performance, I did not install the support module for MySQL.
./configure--with-mysql=/[path to MySQL]--with-apxs=/[path to APXS]
6, return to the prompt state after the make command, waiting to return to the prompt state;
7. Execute the Make install command.
At this point, the system by DSO in the Apache module directory installed PHP, and the Apache httpd.conf file to make the appropriate changes to return to the prompt state. When you get back to the prompt, you also need to make some changes to the Apache httpd.conf file.
1. Find a line containing serveradmin and add your email address as follows:
ServerAdmin you@yourdomain.com
2. Find the line beginning with servername and change it to a real value, for example:
ServerName localhost
3. Find the following subsections:
# 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 PHP 4.0 's AddType no longer becomes a comment, and add the file suffix name that you want to use in PHP, and the above content becomes as follows:
# and for PHP 4.x, use:
#
AddType application/x-httpd-php. php. phtml
AddType Application/x-httpd-php-source. Phps
To save the file, go back to the top level directory and execute the following command to restart Apache:
./bin/apachectl Start
If the error message does not appear at startup, you can test the installed Apache and PHP by creating a file named Phpinfo.php that contains only one line, as follows:

Save this file to the Apache document root directory (htdocs), then open the browser, type the http://localhost/phpinfo.php address, and a number of 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 do install commands, and a new module will appear in the Apache directory module. Just restart Apache to load this new module and everything is OK.
Second, the use of PHP itself dialogue
The most anticipated feature in PHP 4.0 should be support for conversations, and PHP 3.0 users must use third-party software or they won't be able to use conversations, and not support conversations has always been one of PHP's biggest flaws.
As long as users are browsing your site, you can use dialogs to maintain variables related to specific users without having to set up multiple cookies, use hidden table fields, or store information in a database.
Starting a conversation on a Web page will cause the PHP engine to know that you want to start a conversation (if it hasn't started) or continue with the current conversation:
Session_Start ();
Starting a dialog will send a recognition string (for example, 940F8B05A40D5119C030C9C7745AEAD9) to the user via a cookie, and on the server side, a temporary file that matches the recognition string, such as Sess_, will be created. 940F8B05A40D5119C030C9C7745AEAD9, this file contains the registered dialog variables and their values.
The most common example used to show the role of a dialog is access counters. Start the PHP module and make sure that the PHP code is the first line of the file, without spaces, HTML code, and other code before the PHP code. Because the conversation sends a header, if there are spaces and HTML code before session_start (), you get an error message.
If a user does not yet exist for a user, a dialog is started:
Session_Start ();
Then register a variable with the name count:
Session_register (' count ');
After registering a dialog variable, a variable with the name count will exist as long as the dialog is present. Now, the count variable has not been assigned a value, and if you do add 1 to it, its value becomes 1.
$count;
Combine the above, and if you haven't started a conversation, you'll start a conversation; If there is no dialog ID, assign a user a good, register a variable named $count, and perform a plus 1 operation on $count to indicate that the user has visited the page for the first time.


To know the number of times a user accesses this page in the current conversation, simply display the value of the $count variable:
echo "

You ' ve been here $count times.

";
The full 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 is increased by 1, which is cool.


http://www.bkjia.com/PHPjc/445096.html www.bkjia.com true http://www.bkjia.com/PHPjc/445096.html techarticle with more than 3 million Internet sites worldwide, the administrator is using PHP, making it one of the most popular server-side scripting languages. It is characterized by fast running speed, stable and reliable, cross-platform ...

  • 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.