Home  >  Article  >  Backend Development  >  Detailed explanation of the principles and steps of creating an installation program with PHP_PHP Tutorial

Detailed explanation of the principles and steps of creating an installation program with PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:41:23781browse

This article explains the principles and steps of making a PHP installation program
1. The principle of making a PHP installation program
The installation principle of a PHP program is to import the database structure and content into the corresponding database, and reconfigure the connection database from this process Parameters and files, in order to ensure that the installation file is not maliciously used by others, the installation file needs to be modified after the installation is completed.
2. Steps to make a PHP installation program
step1 Check the permissions of the directory or file
step2 Modify or add the configuration file
step3 Check the correctness of the configuration file
step4 Import the database
step5 Lock or delete installation files
3. Make PHP functions used for installation
Check whether the file is writable and return a Boolean value: is_writable("data/config.php");
Check whether the file is readable. Returns a Boolean value: is_readable("data/config.php");
fopen() file operation function, open a file or create a new one
fwrite() file operation function, write content to the file
rename( ) File operation function, rename the file
4. Notes
(1). Check the permissions of the file and related folders, such as cache, generated files, configuration files
(2). Install the file as much as possible It may be independent, can be deleted, and can be renamed.
                   (3). When importing the database, you need to check:
                                                                                                                                                                                                                                                            . Processing
(4). Check the configuration environment and support of various modules, such as: gd2, pdo, rewirte, etc.
5. Example code


  1. $files="data/config.php";
  2. if(!is_writable($files)){
  3. echo "cannot be written!";
  4. }else{
  5. echo "can be written";
  6. }
  7. if(isset($_POST[install])){
  8. $config_str = "
  9. $config_str .= " ";
  10. $config_str .= $mysql_host = " . $_POST[db_host] . ";;
  11. $config_str .= " ";
  12. $config_str .= $mysql_user = " . $_POST[db_user] . ";;
  13. $config_str .= " ";
  14. $config_str .= $mysql_pass = " . $_POST[db_pass] . ";;
  15. $config_str .= " ";
  16. $config_str .= $mysql_dbname = " . $_POST[db_dbname] . ";;
  17. $config_str .= " ";
  18. $config_str .= $mysql_tag = " . $_POST[db_tag] . ";;
  19. $config_str .= " ";
  20. $config_str .= ?>;
  21. $ff = fopen($files, "w ");
  22. fwrite($ff, $config_str);
  23. //=====================
  24. include_once ("data/config.php"); //Embed configuration File
  25. if (!@$link = mysql_connect($mysql_host, $mysql_user, $mysql_pass)) { //Check the database connection
  26. echo "Database connection failed! Please return to the previous page Check the connection parametersReturn to modify";
  27. } else {
  28. mysql_query("CREATE DATABASE `$mysql_dbname`");
  29. mysql_select_db($mysql_dbname);
  30. $sql_query[] = "CREATE TABLE `" . $mysql_tag . "admin_log1` (
  31. `id` int(8) unsigned NOT NULL auto_increment,
  32. `username` varchar(40) NOT NULL COMMENT operation user name,
  33. `types` varchar(60) NOT NULL,
  34. PRIMARY KEY (`id` )
  35. ) ;";
  36. $sql_query[] = "CREATE TABLE `" . $mysql_tag . "admin_log2` (
  37. `id` int(8) unsigned NOT NULL auto_increment,
  38. `username` varchar(40) NOT NULL COMMENT operation user name,
  39. `types` varchar(60) NOT NULL,
  40. PRIMARY KEY (`id `)
  41. ) ;";
  42. $sql_query[] = "CREATE TABLE `" . $mysql_tag . "admin_log3` (
  43. `id` int(8) unsigned NOT NULL auto_increment,
  44. `username` varchar(40) NOT NULL COMMENT operation user name,
  45. `types` varchar(60) NOT NULL,
  46. PRIMARY KEY (` id`)
  47. ) ;";
  48. foreach($sql_query as $val){
  49. mysql_query($val);
  50. }
  51. echo "<script>alert(installation successful!);location.href=index.php</script>";
  52. rename("install.php","install.lock");
  53. }
  54. }
  55. ?>

  56. Fill in the host:
  57. Username: < input type="text" name="db_user" value="root"/>
  58. Password:
  59. Database name:
  60. Data prefix: < input type="text" name="db_tag" value="p_"/>
I hope this article can be useful to you.


http://www.bkjia.com/PHPjc/486158.html

truehttp: //www.bkjia.com/PHPjc/486158.htmlTechArticleThis article explains the principles and steps of making PHP installation programs 1. The principle of making PHP installation programs The installation principle of PHP programs is Import the database structure and content into the corresponding database from here...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn