PHP网站安装程序的原理及代码
发布时间:2023-02-16 12:46:35 所属栏目:PHP 来源:互联网
导读:具体代码: 文件:由于只是展示原理,尽量让其简单化故用小Demo形式演示 install.html为表单填写文件 doAction.PHP 为处理表单文件 dbconfig.PHP 数据库配置文件 index.PHP执行成功跳转页面 install.html !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transi
具体代码: 文件:由于只是展示原理,尽量让其简单化故用小Demo形式演示 install.html为表单填写文件 doAction.PHP 为处理表单文件 dbconfig.PHP 数据库配置文件 index.PHP执行成功跳转页面 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>数据库账号:</td> <td><input type="text" name="username"/></td> </tr> <tr> <td>数据库密码:</td> <td><input type="password" name="password"/></td> </tr> <td>数据库名:</td> <td><input type="text" name="dbname"/></td> </tr> <tr> <td>数据库表前缀:</td> <td><input type="text" name="flag"/></td> </tr> <tr> <td colspan="2" text-align:center;"> <input type="submit" value="安装"/> <input type="reset" value="重置"/> </td> </tr> </table> </form> </center> </body> </html> doAction.PHP <?PHP $filename="dbconfig.PHP"; //配置文件内容 $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)){//检测是否有权限可写 $handle=fopen($filename,"w+"); fwrite($handle,$config); //连接数据库 include_once($filename); if(!@$link=MysqL_connect($host,$user,$pass)){ echo "数据库连接失败,<a href='install.PHP'>返回设置</a>"; (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |