Principles, steps, precautions, and sample code of PHP website installation programs

Source: Internet
Author: User
Tags php website import database

1. Make PHP installationProgramPrinciple
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. ExampleCodeAs follows:

Copy code The Code is as follows: <? PHP
$ Files = "Data/config. php ";
If (! Is_writable ($ files )){
Echo "<font color = Red> cannot be written !!! </Font> ";
} Else {
Echo "<font color = green> writeable </font> ";
}
If (isset ($ _ post [install]) {
$ Config_str = "<? PHP ";
$ 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 the connection parameter <a href = install. php> and return to modify </a> ";
} 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 ");
}
}
?>
<HR size = 1>
<Form action = "" method = "Post">
Enter the Host: <input type = "text" name = "db_host" value = ""/> <br>
User name: <input type = "text" name = "db_user" value = "root"/> <br>
Password: <input type = "text" name = "db_pass" value = ""/> <br>
Database Name: <input type = "text" name = "db_dbname" value = "php100_db"/> <br>
Data Prefix: <input type = "text" name = "db_tag" value = "P _"/> <br>
<Button type = submit name = install> next </button>
</Form>

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.