phpok
2018-02-13 10:50:43 +08:00
代码如下:
$dbconfig = array();
$dbconfig['host'] = $_POST['host'];
$dbconfig['port'] = $_POST['port'];
$dbconfig['user'] = $_POST['user'];
$dbconfig['pass'] = $_POST['pass'];
$dbconfig['data'] = $_POST['data'];
$dbconfig['prefix'] = $_POST['prefix'];
$content = file_get_contents('config.php');
$content = preg_replace('/host\s*=.*/i','host = "'.$dbconfig['host'].'"',$content);
$content = preg_replace('/port\s*=.*/i','port = "'.$dbconfig['port'].'"',$content);
$content = preg_replace('/user\s*=.*/i','user = "'.$dbconfig['user'].'"',$content);
$content = preg_replace('/pass\s*=.*/i','pass = "'.$dbconfig['pass'].'"',$content);
$content = preg_replace('/data\s*=.*/i','data = "'.$dbconfig['data'].'"',$content);
$content = preg_replace('/prefix\s*=.*/i','prefix = "'.$dbconfig['prefix'].'"',$content);
file_put_contents('config.php',$content);
特别说明下,上面代码没有任何过滤,也就是很容易出现安全问题。
建议您可以对 $_POST 进行安全封装下。