For those that want to create a page that will create a base config.php file for them.
<?php
if (isset($_POST['dbserver'])) {
$data = '<?php
$host=$_POST['dbserver'];
$username=$_POST['dbuser'];
$password=$_POST['dbpass'];
$db_name=$_POST['dbname'];
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
?>';
$file = "config.php";
$handle = fopen($file, 'a');
if (fwrite($handle, $data) === FALSE) { echo "Can not write to (".$file.")"; }
echo "Succesfully Wrote to (".$file.")";
fclose($handle);
}
else {
echo "<form name=\"Config Creation\" method=\"post\" action=\"".$PHP_SELF."\">";
echo "Database Host: <input type=\"text\" name=\"dbserver\" value=\"localhost\"><br>";
echo "Database User: <input type=\"text\" name=\"dbuser\" value=\"root\"><br>";
echo "Database Pass: <input type=\"password\" name=\"dbpass\" value=\"password\"><br>";
echo "Database Name: <input type=\"text\" name=\"dbname\" value=\"forums\"><br>";
echo "<input type=\"submit\" value=\"Create Config\"><input type=\"reset\" value=\"Reset\">";
echo "</form>";
}
?>
not bad, relatively useful. a couple of recommendations though.
1) why are you putting your variables in quotes? you don't need to.
$host="'.$_POST['dbserver'].'"; should be: $host = $_POST['dbserver'];
2) check out file_put_contents, it'll save you some trouble - http://php.net/manual/en/function.file-put-contents.php
3) since this is primarily targeted towards inexperienced individuals, i'd add some error checking before just throwing and accepting random post data
4) if you use single quotes in your echo statements ( echo statements, that you could easily avoid using at all ), you wont have to escape your html double quotes
rated 4/10 for mediocre. slightly better coding practices and error checking should be implemented ( again, we really need a better rating system )
I reworked the script and created a gist at https://gist.github.com/CrandellWS/40d3618576bec5d19226