Principles, steps, precautions, and sample code of PHP website installation program-PHP Tutorial

Source: Internet
Author: User
Principles, steps, precautions, and sample code of the PHP website installation program. 1. the principle of creating a PHP installation program in fact, the installation principle of the PHP program is nothing more than importing the database structure and content to the corresponding database, from this process re-configuring the connection to the database 1. how to create a PHP installation program
In fact, the installation principle of the PHP program is nothing more than importing the database structure and content into the corresponding database, and re-configuring the parameters and files for connecting to the database from this process, to prevent malicious use of the installation file, you must modify the installation file after installation.
2. create a PHP installation procedure
Step 1 check the directory or file permissions
Step 2 modify or add the configuration file
Step 3 check the correctness of the configuration file
Step 4 import database
Step 5 lock or delete the installation file
3. create PHP functions for installation
Check whether the file is writable. The return value is is_writable ("data/config. php ");
Check whether the file is readable and return a Boolean value: is_readable ("data/config. php ");
Fopen () file operation function to open a file or create a new
Fwrite () file operation function, write content to the file
Rename () file operation function, rename the file
4. Notes
(1). check the permissions of files and related folders, such as caching, generating files, and configuring files.
(2) Install files as independent as possible, which can be deleted and renamed.
(3) During database import, check:
A. Check whether you have the permission to create a database.
B. whether a database with the same name exists
C. check whether the database import size is segmented.
(4) Check the configuration environment and support of various modules, such as gd2, pdo, and rewirte.
5. the sample code is as follows:

The code is as follows:


$ Files = "data/config. php ";
If (! Is_writable ($ files )){
Echo "cannot be written !!! ";
} Else {
Echo "writable ";
}
If (isset ($ _ POST [install]) {
$ Config_str =" $ Config_str. = "\ n ";
$ Config_str. = '$ mysql_host = "'. $ _ POST [db_host]. '";';
$ Config_str. = "\ n ";
$ Config_str. = '$ mysql_user = "'. $ _ POST [db_user]. '";';
$ Config_str. = "\ n ";
$ Config_str. = '$ mysql_pass = "'. $ _ POST [db_pass]. '";';
$ Config_str. = "\ n ";
$ Config_str. = '$ mysql_dbname = "'. $ _ POST [db_dbname]. '";';
$ Config_str. = "\ n ";
$ Config_str. = '$ mysql_tag = "'. $ _ POST [db_tag]. '";';
$ Config_str. = "\ n ";
$ Config_str. = '?> ';
$ Ff = fopen ($ files, "w + ");
Fwrite ($ ff, $ config_str );
// ====================================
Include_once ("data/config. php"); // embed the configuration file
If (! @ $ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass) {// check the database connection status
Echo "database connection failed! Please return to the previous page to check connection parameters and return to modify ";
} Else {
Mysql_query ("create database '$ mysql_dbname '");
Mysql_select_db ($ mysql_dbname );
$ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log1 '(
'Id' int (8) unsigned not null auto_increment,
'Username' varchar (40) not null comment' operation user name ',
'Types' varchar (60) not null,
Primary key ('id ')
);";
$ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log2 '(
'Id' int (8) unsigned not null auto_increment,
'Username' varchar (40) not null comment' operation user name ',
'Types' varchar (60) not null,
Primary key ('id ')
);";
$ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log3 '(
'Id' int (8) unsigned not null auto_increment,
'Username' varchar (40) not null comment' operation user name ',
'Types' varchar (60) not null,
Primary key ('id ')
);";
Foreach ($ SQL _query as $ val ){
Mysql_query ($ val );
}
Echo "script" alert ('installation successful! '); Location. href = 'index. php' script ";
Rename ("install. php", "install. lock ");
}
}
?>



In fact, the installation principle of the PHP program is nothing more than importing the database structure and content to the corresponding database, and re-configuring the connection to the database from this process...

Related Article

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.