日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PHP网站安装程序的原理及代码

發(fā)布時間:2025/4/16 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP网站安装程序的原理及代码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原文:PHP網(wǎng)站安裝程序的原理及代碼

原理:

其實PHP程序的安裝原理無非就是將數(shù)據(jù)庫結(jié)構(gòu)和內(nèi)容導入到相應的數(shù)據(jù)庫中,從這個過程中重新配置連接數(shù)據(jù)庫的參數(shù)和文件,為了保證不被別人惡意使用安裝文件,當安裝完成后需要修改安裝文件。

步驟:

1、檢查目錄或文件的權(quán)限?
2、修改或填加配置文件?
3、檢查配置文件正確性?
4、導入數(shù)據(jù)庫?
5、鎖定或刪除安裝文件?

具體代碼:


文件:由于只是展示原理,盡量讓其簡單化故用小Demo形式演示

install.html  為表單填寫文件

doAction.php   ?為處理表單文件

dbconfig.php ?數(shù)據(jù)庫配置文件

index.php  執(zhí)行成功跳轉(zhuǎn)頁面

install.html

?

?

?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>安裝程序</title> </head> <body><center><h2>PHP在線安裝程序</h2><hr/><form action="doAction.php" method="post"><table><tr><td>主機地址:</td><td><input type="text" name="host"/></td></tr><tr><td>數(shù)據(jù)庫賬號:</td><td><input type="text" name="username"/></td></tr><tr><td>數(shù)據(jù)庫密碼:</td><td><input type="password" name="password"/></td></tr><td>數(shù)據(jù)庫名:</td><td><input type="text" name="dbname"/></td></tr><tr><td>數(shù)據(jù)庫表前綴:</td><td><input type="text" name="flag"/></td></tr><tr><td colspan="2" style="text-align:center;"><input type="submit" value="安裝"/><input type="reset" value="重置"/></td></tr></table></form></center> </body> </html>

doAction.php

?

<?php$filename="dbconfig.php";//配置文件內(nèi)容$config='<?php';$config.="\n";$config.='$host="'.$_POST["host"].'";';$config.="\n";$config.='$user="'.$_POST["username"].'";';$config.="\n";$config.='$pass="'.$_POST["password"].'";';$config.="\n";$config.='$dbname="'.$_POST["dbname"].'";';$config.="\n";$config.='$flag="'.$_POST["flag"].'";';$config.="\n";$config.="?>";if(is_writable($filename)){//檢測是否有權(quán)限可寫$handle=fopen($filename, "w+");fwrite($handle, $config);//連接數(shù)據(jù)庫include_once($filename);if(!@$link=mysql_connect($host,$user,$pass)){echo "數(shù)據(jù)庫連接失敗,<a href='install.php'>返回設(shè)置</a>";}else{mysql_query("create database if not exists `$dbname`");mysql_select_db($dbname,$link);//建表語句$sql[]="CREATE TABLE IF NOT EXISTS `".$flag."access` (`role_id` smallint(6) unsigned NOT NULL,`node_id` smallint(6) unsigned NOT NULL,`level` tinyint(1) NOT NULL,`module` varchar(50) DEFAULT NULL,KEY `groupId` (`role_id`), KEY `nodeId` (`node_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8";$sql[]="CREATE TABLE IF NOT EXISTS `".$flag."node` (`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(20) NOT NULL,`title` varchar(50) DEFAULT NULL,`status` tinyint(1) DEFAULT '0',`remark` varchar(255) DEFAULT NULL,`sort` smallint(6) unsigned DEFAULT NULL,`pid` smallint(6) unsigned NOT NULL,`level` tinyint(1) unsigned NOT NULL,PRIMARY KEY (`id`),KEY `level` (`level`),KEY `pid` (`pid`),KEY `status` (`status`),KEY `name` (`name`)) ENGINE=MyISAM DEFAULT CHARSET=utf8";$sql[]="CREATE TABLE IF NOT EXISTS `".$flag."role` (`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(20) NOT NULL,`pid` smallint(6) DEFAULT NULL,`status` tinyint(1) unsigned DEFAULT NULL,`remark` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`),KEY `pid` (`pid`),KEY `status` (`status`)) ENGINE=MyISAM DEFAULT CHARSET=utf8";$sql[]="CREATE TABLE IF NOT EXISTS `".$flag."role_user` (`role_id` mediumint(9) unsigned DEFAULT NULL,`user_id` char(32) DEFAULT NULL,KEY `group_id` (`role_id`),KEY `user_id` (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8";foreach ($sql as $value) {//由于mysql_query不支持一次性執(zhí)行多條語句,所以用for循環(huán)遍歷mysql_query($value);}echo "<script>window.location='index.php';</script>";rename("install.html", "install.lock");}}else{echo "您沒有權(quán)限操作。";} ?>

?

dbconfig.php

?

<?php $host="localhost"; $user="root"; $pass=""; $dbname="demo"; $flag="lcw_"; ?>

?

index.php

?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>首頁</title> </head> <body><h2>^_^ 數(shù)據(jù)導入成功。</h2> </body> </html>

?

執(zhí)行完安裝文件(自動修改文件名):

數(shù)據(jù)庫導入成功!

?

總結(jié)

以上是生活随笔為你收集整理的PHP网站安装程序的原理及代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。