Home >Backend Development >PHP Tutorial >Four Common PHP Programming Tips_PHP Tutorial

Four Common PHP Programming Tips_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:45709browse

Four common tips for PHP programming:
1. Configure the PHP file directory

As a scripting language interpreted and executed by the server, the PHP program is placed in a directory that can be accessed by the server. Generally, it can be modified by modifying Apache's httpd .conj to configure, for example, our sentence in the file:
 Alias ​​/test/ "d:brhpwebsitebrhp/" Then enter: "http://localhost/test/+PHP file name" on the browser side. Access the PHP file under d:brhpwebsitebrhp/; it can be seen that this line is just an alias for the directory where the PHP file is stored.
Secondly, you can also get the directory where the server files are stored by specifying the DocumentRoot path. Find the following two lines in httpd.conj. The path can be specified at will. Your PHP files can also be placed in this directory, and the server can also run. They, such as "http://localhost/+PHP file name".
Generally, it is better to put PHP files in the same place for easy management, and put other files in another place.
DocumentRoot "C:/usr/bin/html/"
2. Index file of the server-side directory
In httpd.conj, there is a line: DirectoryIndex index.html
This line specifies the default directory The open file is index.html. When a directory is accessed, the server will automatically search for index.html. If it does not exist, a list of all files in the directory will be displayed. The default open file can be changed to something else, such as index.php3 Wait, but maybe we have many directories, whether they store pictures, text and other materials, or directories where PHP files or other files are stored. We don't want users to be able to see the file list in the directory, in httpd.conj A .htacess file is specified, which generates a directory index file. For example, we use WordPad to create a .htacess file:
  # .htacess #
DirectoryIndex error_open.php
Then create an error warning file:
  # error_open.php #
The error_open.php is the permission error warning file. Place these two files in all protected directories. When the user attempts to open the directory, it will automatically redirect to execute error_open.php and display the error warning. .
 3. Directory deletion is implemented cleverly
We know that there is a rename() function in PHP4 for/win32 that can support renaming of directories/files, such as: rename(oldpath, newpath) // oldpath is a file or The original path of the directory; // newpath is the newly defined path;
Implementation of renaming oldpath to newpath.
There is no function to delete directories/files in PHP4. How to delete them? We know that there is a temporary file directory configuration line in php.ini used to complete the HTTP upload operation: upload_tmp_dir=;
PHP4 supports the configuration of this temporary directory (PHP3 does not support it). When the upload operation is completed, the temporary directory will be automatically cleared. , well, we can use it to delete files/directories cleverly, such as setting: upload_tmp_dir="d:brhpwebsitebrhp/tmp/"; To delete a directory path, execute: tmp="d:brhpwebsitebrhp/tmp/; " rename( path, tmp) ?>;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445188.htmlTechArticleFour common tips for PHP programming: 1. Configure the PHP file directory as a script language for server-side interpretation and execution, and place PHP programs In a directory that can be accessed by a server, you can generally modify it...
Statement:
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