PHP is used by administrators of more than 3 million Internet websites around the world, 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 understanding of 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 and dynamic mode ( DSO), CGI binary mode.
Since it is easy to maintain and upgrade, I strongly 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, just run "make clean", add new configuration options, and then run "make" and "make install", one 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 the /usr/local/ or /opt/ directory, or any directory you specify;
3. Run Gunzip to decompress the file and get the suffix .tar file;
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 file was installed in step 4);
6. Type the following command to prepare for compiling Apache, replacing the paths with your own [path], for example, /usr/local/apache[version], now the new value of mod_so has been set, which 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 any directory you specify;
3. Run Gunzip to decompress the file and get a file with the suffix .tar;
4. Execute the following command Install the file in the php-[version] directory:
tar -xvf php-[version]
5. Enter the /usr/local/php-[version] directory or in step 4 The directory specified in;
At this point, preparations have been made to install PHP in DSO mode. The only configuration option that needs to be modified is with-apxs (this is a file in the bin directory of Apache). 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 , wait to return to the prompt state;
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 shown below:
ServerAdmin you@yourdomain.com
2. Find the line that starts with ServerName line, change it to a real 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 content of these lines so that the AddType of PHP 4.0 is no longer a comment, and add the file suffix you want to use in PHP. The above content becomes the following:
# 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 Information, you can test the installed Apache and PHP by creating a file named phpinfo.php with only one line of content as shown below:
phpinfo() ?>
Save this file to Apache’s document root directory (htdocs), then open the browser and type in the http://localhost/phpinfo.php address. 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 directory module will appear in Apache module, as long as you restart Apache to load this new module, everything will be OK.
2. Dialogue using PHP itself
The most anticipated feature of PHP 4.0 should be the support for dialogue. Users of PHP 3.0 must use third-party software, otherwise they cannot use dialogue. It is not supported. Dialogue has always been one of PHP's biggest shortcomings.
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 conversation will send an identification string to the user through a cookie (for example, 940f8b05a40d5119c030c9c7745aead9). On the server side, a temporary file matching the identification string will be created, such as sess_940f8b05a40d5119c030c9c7745aead9. This file contains the registered conversation variables and their value.
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 not yet a user for a user, start a conversation:
session_start();
Then Register a variable named count:
session_register(count);
After registering a conversation variable, as long as the conversation 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 together, if a conversation has not been started, a conversation will be started; if a conversation id does not exist, just specify one for the user , register a variable named $count, and add 1 to $count to indicate that the user has visited the webpage for the first time.
To know how many times the user has visited this page in the current conversation, just display the value of the $count variable:
echo "
Youve been here $count times.< ;/p>";
All access counter codes are 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 increases by 1, which is cool.
You can also register an array variable in the conversation. Suppose we register a variable named $faves:
$faves = array (chocolate,coffee,beer,linux);
You can register an array variable just like a simple variable:
session_register(faves);
There is no difference between referencing an array variable and referencing a simple variable. If a user is on a web page When pointing out the hobbies in life, you can register his hobbies in an array variable called $faves, and then you can easily display these hobbies on another web page:
< ;?
session_start();
echo "My user likes:
- ";
- $v"; }
echo "
while (list(,$v) = each ($faves)) {
echo "
?>
Then you get a list of the user’s hobbies.
Dialog variables cannot be overwritten by query strings, which means we cannot enter http:///www.yourdomain.com/yourscript.php?count=56 to specify a new value for the registered variable $count. This Important point for security: only delete an unregistered dialog variable in a server-side script.
If you want to completely delete a conversation variable, you first need to unregister it from the system:
session_unregister(count);
The script to completely delete a conversation variable is very simple , as shown below:
Session_destroy();
Using session variables can reduce the frequency of accessing the database, make the code clearer, and can reduce the number of cookies sent to the user. It is the most The easy way out.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
