PHP programming skills)

Source: Internet
Author: User
Common PHP programming skills. the PHP file directory is configured as the script language for server-side interpretation and execution. The PHP program is placed in a directory accessible to a server. generally, Apache httpd can be modified. conj configuration. for example, if we enter Aliastestd: phpwebsitephp in the file, enter "localho PHP programming skills

1. configure the php file directory

As the script language for server interpretation and execution, the PHP program is placed in a directory accessible to a server. generally, Apache httpd can be modified. conj configuration, for example, the following sentence in this file:

Alias/test/"d:/phpwebsite/php/", enter "http: // localhost/test/+ PHP file name" in the browser to access d: the php file under/phpwebsite/php/. it can be seen that this line is just an alias for the directory where the php file is stored.

You can also specify the DocumentRoot path to get the directory where the server files are stored. conj finds the following two lines. The path can be specified at will, and your php file can be stored in this directory. the server can also run them, such as "http: // localhost/+ PHP file name ".

Generally, it is better to place the php file in the same place for convenient management, while other files are placed in another place.

DocumentRoot "C:/usr/bin/html /"

2. index files in the server directory
In httpd. conj, there is a line:
DirectoryIndex index.html

The specified directory is named index.html. when a directory is created, the server automatically finds index.html. if the directory does not exist, the server displays the list of all files in the directory. by default, the opened files can be changed to other files, such as index. php3 and so on, but we may have many directories, whether it is for storing images, text and other materials, or for storing php files or other files, we do not want users to see the file list in the directory, in httpd. a. htacess file, which generates a directory index file. for example, we use a WordPad to create a directory index file. htacess file:

#. Htacess #
DirectoryIndex error_open.php
Create an error warning file:
# Error_open.php #


Here, error_open.php is the Permission error warning file, which stores the 2 files in all protected directories. when a user attempts to open the directory, the system automatically redirects to error_open.php and displays an error warning.

3. Directory deletion clever implementation
We know that there is a rename () function in PHP4 for/win32 that supports renaming directories/files, such:
Rename (oldpath, newpath) // oldpath is the original path of the file or directory;
// Newpath is the new defined path;

To change the oldpath to newpath.

PHP4 does not have a function to delete directories/FILES. how can this function be deleted? We know that php. ini has a temporary file directory configuration line used to complete the HTTP upload operation:
Upload_tmp_dir =;

PHP4 supports the configuration of this temporary directory (PHP3 is not supported). when the upload operation is complete, the temporary directory is automatically cleared. with this, we can skillfully delete files/directories, for example, set upload_tmp_dir = "d:/phpwebsite/php/tmp /";
To delete a directory path, run:

Tmp = "d:/phpwebsite/php/tmp /;"
Rename (path, tmp)
?>

After the file or directory path is renamed to tmp, all files/directories under the tmp directory are automatically cleared, and the deletion is completed.

4. quickly create a MySql database table

PHP and MySql databases are perfectly integrated. on the webpage, for example, when a new user who publishes a work in a forum or bookstore, we need to write his remarks online into the database, create a data table for the user in the corresponding database. It is very easy to create a new MySQL empty database under win32. just create a folder under the "/mysql/data/" directory, such as "/usrinfo. To add a new table to the database, you can use the following program:

# Connect. mysql -- connect to the database #
Connection = mysql_connect ();
Mysql_select_db ("usrinfo", connection );
?>
# Make. php -- create a data table with the table name in the following structure #
// Call connect. mysql
Require ("connect. mysql ");
// Check whether a table with the table name as the user name exists?
Query = "select count (*) from usrname ";
Result = mysql_db_query (query );
// If the parameter does not exist, it is created. if the parameter exists, it is an old user;
If (! Result ){
Mysql_query ("
Create table usrname (
Id tinyint (6 ),
Title text,
Body longtext,
Dateof date;
Timeof time;
) ") Or die (mysql_error ());
}
// Insert a new data part to the data table
?>



Original Author: Rogi
Source: Huajun Software Park

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.