Principles and procedures for making PHP installers 56

Source: Internet
Author: User
Tags button type import database

Principles and procedures for making PHP installers 56

1. The principle and procedure of making PHP installation program
Check the permissions of a directory or file----Modify or add a configuration file---Check the profile
Confirm---Import database----lock or delete installation files

Principle: In fact, the installation principle of PHP program is simply to import the database structure and content into
In the corresponding database, reconfigure the parameters and files of the connected database from this process to
To ensure that no one else is malicious. installation files are required to be modified after installation is complete

2 Creating PHP functions for installation
Is_writable ("data/config.php");
Is_writable () checks whether a file is writable, used to determine file permissions, and a similar function
Is_readable () checks if the file is readable and returns a Boolean value

fopen () file operation function, open a file or create a new fwrite () file Operation function
, write content to file rename () file operation function, rename file

3. Precautions for making and installing
Check file permissions and related folders, such as cache, generate files, configuration files
installation files are as independent as possible and can be deleted and renamed.
When you import a database, you need to check:
A. Check if you have permission to set up a database
b, whether the database exists with the same name
C, consider whether the size of the database import is fragmented
Check the configuration environment, the support of various modules, such as: GD2, Pdo,rewirte, etc.

install.php
--------------------------------------------------------------------
------------------------------
<?php

$files = "data/config.php";

if (!is_writable ($files)) {
echo "<font color=red> not writable!!! </font> ";
}else{
echo "<font color=green> writable </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"); Embedding the configuration file
if ([email protected] $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 <a
Href=install.php> back 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 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 "<script>alert (' installed as
'); location.href= ' index.php ' </script> ';
Rename ("install.php", "Install.lock");

}

}

?>

<link href= "Common.css" Type=text/css rel=stylesheet>
<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>

config.php
--------------------------------------------------------------------
---------------------- --------
<?php
$mysql _host = "localhost";
$mysql _user = "root";
$mysql _pass = "";
$mysql _dbname = "new_php100";
$mysql _tag = "New_";
?

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.