Questo lo so.
E' proprio per questo che non capisco come mai ci siano degli header nel bel mezzo del codice quando l'output è già bello che inviato.
Questo è il codice completo dello script in questione
Codice PHP:
<?php
###################################################
# #
# PhpEasyDump v0.1 #
# #
# Autore: Gabriele Cannizzaro aka Scitrek #
# #
# L'utilizzo è libero per scopi NON commerciali #
# #
###################################################
function list_tables($db_name) {
$sql_query = mysql_list_tables($db_name);
for ($i=0; $i<mysql_num_rows($sql_query); $i++) {
$sql_tabs[] = mysql_tablename($sql_query, $i);
}
return $sql_tabs;
}
function dump_structure($table) {
$sql_query = mysql_query("SHOW CREATE TABLE ".$table);
$sql_array = mysql_fetch_row($sql_query);
return $sql_array[1].";";
}
function dump_data($table) {
$content = "";
$sql_query = mysql_query("SELECT * FROM ".$table);
while ($sql_row = mysql_fetch_row($sql_query)) {
$content .= "INSERT INTO `".$table."` VALUES (";
for($i=0; $i<mysql_num_fields($sql_query); $i++) {
if (!isset($sql_row[$i])) {$content .= "NULL,";}
elseif ($sql_row[$i] !== "") {$content .= "'".addslashes($sql_row[$i])."', ";}
else {$content .= "'', ";}
}
$content = substr($content,0,-2);
$content .= ");\n";
}
return substr($content,0,-1);
}
function data() {
$giorni = array("Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato");
$mesi = array("","Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
return $giorni[date("w")]." ".date("j")." ".$mesi[date("n")]." ".date ("Y");
}
function ora() {return date("H:i");}
if (!isset($_SERVER)) {$_SERVER = $HTTP_SERVER_VARS;}
$sysname = "PhpEasyDump v0.1";
$version = "0.1";
if (isset($_POST['action']) && $_POST['action'] == "dump") {
$con = @mysql_connect($_POST['db_host'],$_POST['db_user'],$_POST['db_pass']); if(!$con) exit("[b]ERRORE[/b]: Impossibile stabilire una connessione al database MySQL.");
$sel = @mysql_select_db($_POST['db_name']); if(!$sel) exit("[b]ERRORE[/b]: Impossibile selezionare il database MySQL.");
$sql_tables = list_tables($_POST['db_name']);
$dump = "# PhpEasyDump v0.1
# Autore: Gabriele Cannizzaro aka Scitrek
# L'utilizzo è libero per scopi NON commerciali
#
# Host: ".$_POST['db_host']."
# Generato: ".data()." alle ore ".ora()."
# Versione MySQL: ".mysql_get_server_info()."
# Versione PHP: ".phpversion()."
# Database : `".$_POST['db_name']."`
# --------------------------------------------------------
";
for ($n=0; $n<count($sql_tables); $n++) {
$dump .= "
#
# Struttura della tabella `".$sql_tables[$n]."`
#
";
if ($_POST['drop'] == "si") {$dump .= "DROP TABLE IF EXISTS `".$sql_tables[$n]."`;\n";}
$dump .= dump_structure($sql_tables[$n])."
#
# Dump dei dati per la tabella `".$sql_tables[$n]."`
#
".dump_data($sql_tables[$n])."
# --------------------------------------------------------
";
}
$dump = substr($dump,0,-62);
$fname = $_POST['prefix']."backup.sql";
if (file_exists($fname)) {unlink($fname);}
$fopen = fopen($fname, "wb");
fwrite($fopen, $dump);
fclose($fopen);
header("Content-type: \"application/octet-stream\"");
header("Content-Disposition: attachment; filename=\"".basename($fname)."\"");
header("Content-transfer-encoding: \"binary\""); readfile($fname);
unlink($fname);
}
else {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<!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>
<title>PhpEasyDump</title>
<style>
.menu_table {
background-color: #505050;
border: 0px;
width: 370px;
}
.menu_td {
font-family: Tahoma, Verdana, sans-serif;
font-size: 10px;
font-weight: bold;
border-color: #000000;
background-color: #E9EDF5;
cursor: hand;
width: 20%;
text-align: center;
}
.body_td {
font-family: Tahoma, Verdana, sans-serif;
font-size: 12px;
font-weight: bold;
border-color: #000000;
background-color: #FFFFFF;
cursor: hand;
width: 100%;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<div align=\"center\">
<table class=\"menu_table\" cellpadding=\"2\" cellspacing=\"1\">
<tr>
<td class=\"menu_td\">
PhpEasyDump v0.1
</td>
</tr>
</table>
</div>
<div align=\"center\">
<table class=\"menu_table\" cellpadding=\"2\" cellspacing=\"1\">
<tr>
<td class=\"body_td\">
<form name=\"dump_form\" action=\"".basename($_SERVER['PHP_SELF'])."\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"dump\"></input>
[b]Host[/b]
<input type=\"text\" name=\"db_host\" size=\"15\" maxlength=\"15\"></input>
[b]Username[/b]
<input type=\"text\" name=\"db_user\" size=\"15\" maxlength=\"15\"></input>
[b]Password[/b]
<input type=\"password\" name=\"db_pass\" size=\"15\" maxlength=\"10\"></input>
[b]Nome del database[/b]
<input type=\"text\" name=\"db_name\" size=\"15\" maxlength=\"15\"></input>
<input type=\"checkbox\" name=\"drop\" value=\"si\">Aggiungi 'drop table'</input>
<input type=\"submit\" value=\"Esegui dump\"></input>
</form>
</td>
</tr>
</table>
</div>
<div align=\"center\">
<table class=\"menu_table\" cellpadding=\"2\" cellspacing=\"1\">
<tr>
<td class=\"menu_td\">
Copyright © 2003 Gabriele Cannizzaro [Scitrek] - Tutti i diritti riservati
</td>
</tr>
</table>
</div>
</body>
</html>";
}
?>
E queste sono le righe "incriminate":
header("Content-type: \"application/octet-stream\"");
header("Content-Disposition: attachment; filename=\"".basename($fname)."\"");
header("Content-transfer-encoding: \"binary\"");
Scusa ma non sapevo come evidenziarle nel codice all'interno dei tag
[PHP]