重複の可能性:
PHP によって既に送信されたヘッダー
ファイルを作成する機能があります。成功した場合は、ユーザーを X ページにリダイレクトしたい..この場合は 1.php.... しかし、機能していません。PHPスクリプトは一番上にあります...技術的に言えば動作するはずです
createFile() 関数内に配置header ()
すると機能しますが、if ステートメント内に配置すると機能しません....
<?php
//DB Config File
$dbFile = 'dbconfig.php';
function createfile ($dbFile) {
//Creates File and populates it.
$fOpen = fopen($dbFile, 'w');
$fString .= "<?php\n";
$fString .= "// Database Constants\n";
$fString .= "define(\"DB_SERVER\", \"$server\");\n";
$fString .= "define(\"DB_USER\", \"$username\");\n";
$fString .= "define(\"DB_PASS\", \"$password\");\n";
$fString .= "define(\"DB_NAME\", \"$dbname\");\n";
$fString .= "?>";
fwrite($fOpen, $fString);
fclose($fOpen);
}
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$server = $_POST['server'];
$dbname = $_POST['dbname'];
try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);
if ($db) { //if succesful at connecting to the DB
if (file_exists($dbFile)){
if (is_readable($dbFile) && is_writable($dbFile)){
//Creates File, populates it and redirects the user
if (createfile($dbFile)) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '1.php';
header("Location: http://$host$uri/$extra");
exit ();
}
} else {
$msg = "2The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission."; }
} else {
//Creates File, populates it and redirects the user
if (createfile($dbFile)) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '1.php';
header("Location: http://$host$uri/$extra");
exit ();
}
}
}
} catch (PDOException $e) { //Catchs error if can't connect to the db.
$msg = 'Connection failed: ' . $e->getMessage();
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="iForm" method="post" action="install.php">
<label id="username" name="username">Username</label>
<input id="username" name="username"/>
<label id="password" name="password">Password</label>
<input id="password" name="password" />
<label id="server" name="server">Server</label>
<input id="server" name="server"/>
<label id="dbName" name="dbname">dbName</label>
<input id="dbName" name="dbname"/>
<input type="submit" name="submit" value="submit" />
</form>
<p id="error"><?php echo $msg ?></p>
</body>
</html>