This article explains the principle and steps of PHP production and installation program
1, the principle of making PHP installation program
The installation principle of the PHP program is to import the database structure and content into the corresponding database, from the process to reconfigure the parameters and files of the database, in order to ensure that no one else malicious use of the installation files, when the installation is completed need to modify the installation files.
2. Steps to make PHP installation program
Step1 checking the permissions of a directory or file
Step2 Modify or add a configuration file
Step3 checking configuration file correctness
STEP4 Importing databases
STEP5 locking or deleting installation files
3, make the installation of PHP functions
Check if the file is writable and return a Boolean value: Is_writable ("data/config.php");
Checks if the file is readable and returns a Boolean value: Is_readable ("data/config.php");
fopen () file operation function, open a file or create a new
Fwrite () file operation function, write content to file
Rename () file operation function, renaming files
4. Precautions
(1). check files and associated folder permissions, such as cache, makefile, config file
(2). installation files are as independent as possible, can be deleted, can be renamed.
(3). When the database is imported, you need to check:
A. Checking for permissions to establish a database
B. Whether the database exists with the same name
C. Consider whether the size of the database import is fragmented
(4). Check the configuration environment, the support of various modules, such as: GD2, Pdo,rewirte, etc.
5. Instance Code
-
- $files = "data/config.php";
- if (!is_writable ($files)) {
- echo "Not writable!!! ";
- }else{
- echo "writable";
- }
- if (Isset ($_post[install])) {
- $config _str = "
- $config _str. = "";
- $config _str. = $mysql _host = ". $_post[db_host]. ";;
- $config _str. = "";
- $config _str. = $mysql _user = ". $_post[db_user]. ";;
- $config _str. = "";
- $config _str. = $mysql _pass = ". $_post[db_pass]. ";;
- $config _str. = "";
- $config _str. = $mysql _dbname = ". $_post[db_dbname]. ";;
- $config _str. = "";
- $config _str. = $mysql _tag = ". $_post[db_tag]. ";;
- $config _str. = "";
- $config _str. =?>;
- $FF = fopen ($files, "w");
- Fwrite ($FF, $config _str);
- //=====================
- Include_once ("data/config.php"); Embedding the configuration file
- if (!@ $link = mysql_connect ($mysql _host, $mysql _user, $mysql _pass)) {//Check database connection condition
- echo "Database connection failed! Please go back to the previous page to check the connection parameters back 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 (+) not NULL COMMENT operation user name,
- ' Types ' varchar is not NULL,
- PRIMARY KEY (' id ')
- ) ;";
- $sql _query[] = "CREATE TABLE". $mysql _tag. "Admin_log2" (
- ' ID ' int (8) unsigned not NULL auto_increment,
- ' username ' varchar (+) not NULL COMMENT operation user name,
- ' Types ' varchar is not NULL,
- PRIMARY KEY (' id ')
- ) ;";
- $sql _query[] = "CREATE TABLE". $mysql _tag. "Admin_log3" (
- ' ID ' int (8) unsigned not NULL auto_increment,
- ' username ' varchar (+) not NULL COMMENT operation user name,
- ' Types ' varchar is not NULL,
- PRIMARY KEY (' id ')
- ) ;";
- foreach ($sql _query as $val) {
- mysql_query ($val);
- }
- echo "";
- Rename ("install.php", "Install.lock");
- }
- }
- ?>
-
I hope this article will get you something.
http://www.bkjia.com/PHPjc/486158.html www.bkjia.com true http://www.bkjia.com/PHPjc/486158.html techarticle This article explains the PHP production installation program principle and step 1, the principle of making PHP installation program PHP program installation principle is to import the database structure and content into the corresponding database, from ...