The principle, procedure, Precautions and sample code _php technique of PHP website installer

Source: Internet
Author: User
Tags button type php website create database import database

1. The principle of making PHP installation program
In fact, the installation of the PHP program is nothing more than the database structure and content into the corresponding database, from this process to reconfigure the database parameters and files, in order to ensure that no one else malicious use of the installation files, when the installation is completed, you need to modify the installation files.
2. Steps to make a PHP installer
Step1 permissions to check directories or files
Step2 Modify or fill in the configuration file
STEP3 Check configuration file correctness
STEP4 Import Database
STEP5 Lock or delete installation files
3. Create a PHP function for installation
Check whether the file is writable and return a Boolean value: Is_writable ("data/config.php");
Check whether the file is readable and return a Boolean value: Is_readable ("data/config.php");
fopen () file action function, open a file or create a new
Fwrite () file action function, write content to file
Rename () file operation function, renaming file
4. Matters needing attention
(1). check files and related folder permissions, such as caching, generating files, configuration files
(2). installation files are as independent as possible and can be deleted and renamed.
(3). When the database is imported, you need to check:
A. Checking for permissions to establish a database
B. Existence of a database with the same name
C. Consider whether the size of the database import is handled in a segmented
(4). Check the configuration environment, the support of various modules, such as: GD2, Pdo,rewirte, etc.
5. The sample code is as follows

Copy Code code as follows:

<?php
$files = "data/config.php";
if (!is_writable ($files)) {
echo "<font color=red> not writable!!! </font> ";
}else{
echo "<font color=green> can write </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 configuration file
if (!@ $link = mysql_connect ($mysql _host, $mysql _user, $mysql _pass)) {//Check database Connectivity
echo Database connection Failed! Please return to the previous page to check the connection parameters <a href=install.php> 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 not NULL COMMENT ' operation user name ',
' Types ' varchar 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 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 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");
}
}
?>
&LT;HR size=1>
<form action= "" method= "POST" >
Fill in 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.