Mengoper variabel array ke halaman berbeda

saya punya url bernama install.php, didalamnya ada sebuah form yang mengambil data. lalu, semua data saya kumpulkan jadi 1 dalam variable berbentuk array. variabel nya bernama $db_connect;
if (isset($_POST['submit'])) {
    if ($data == $_POST['csrf']) {
        $db_connect = [
            'HOST'  =>  $_POST['dbhost'],
            'USER'  =>  $_POST['dbuser'],
            'PASS'  =>  $_POST['dbpass'],
            'NAME'  =>  $_POST['dbname'],
        ];
        
        unset($_SESSION['csrf']);
        header('Location: install.php?success=true');
    } else {
        die($data . '==' . $_POST['csrf']);
    }
}
lalu, dikode itu kan saya melakukan redirect ke install.php?success=true dan saya coba untuk mengeluarkannya pada halaman tersebut.
<?php if ($_GET['success'] == true) : ?>
    <div class="border p-3 bg-light" style="border-radius:4px;">
        <p class="alert alert-warning">Copy this script below, and create a file "config.php" into root directory examygo and paste to it!</p>
        <div class="card bg-light p-3" style="border-radius:4px;">
            <div class="border p-2 mb-3" style="border-radius:4px;">
                <p><?= htmlspecialchars('<?php') ?></p>
                <p><?= htmlspecialchars('//copy this and paste it into a config.php file') ?></p>
                <p>$get_HOST = <?= "'" . $db_connect['HOST'] . "';"; ?></p>
                <p>$get_USER = <?= "'" . $db_connect['USER'] . "';"; ?></p>
                <p>$get_PASS = <?= "'" . $db_connect['PASS'] . "';"; ?></p>
                <p>$get_NAME = <?= "'" . $db_connect['NAME'] . "';"; ?></p>
                <p><?= "?>" ?></p>
            </div>
            <p class="alert alert-danger"><i>Important!: pastikan konfigurasi yang tertera diatas sesuai dengan database milik anda dan sudah membuat file config.php</i></p>
            <form action="" method="post">
                <input type="hidden" name="csrf" value="<?= $_SESSION['csrf']; ?>" />
                <button name="confirm" type="submit" class="btn btn-primary">KONFIRMASI</button>
            </form>
        </div>
    </div>
<?php endif; ?>
tapi kok gak bisa ya? apa kode saya salah ? tolong bantuannya. terima kasih :)
avatar HabibulUmam

@HabibulUmam

59 Kontribusi 10 Poin


Jawaban

ini ceritanya ingin membuat 1 click installation y ? mungkin saya ada refrensinya
<html>
<title>Welcome</title>
<style>
#form_login{
margin-top:50px;
margin-left:400px;
padding:20px;
width:170px;
border:2px solid;
border-radius:10px; 
border-color:#dedede;
}
</style>

<body>
<div id="form_login" align="center">
<h3 align="center">Instalasi ...</h1>
<form method="POST" action="install2.php">
Host <br/><input type="text" name="host"/><br/>
Username  <br/><input type="text" name="user"/><br/>
Password  <br/><input type="password" name="pass"/><br/>
database name <br/> <input type="text" name="db"/><br/>

<input type="submit" name="submit" value="next >"/>
</form>
</div>
</body>
</html>
Halaman Proses
<html>
<title>Instalasi Sistem</title>
<script type="text/javascript">
    var counter = 10;
    function countDown()
    {
        if(counter>=0)
        {
            document.getElementById("timer").innerHTML = counter;
        }
        counter -= 1; 

        var counter2 = setTimeout("countDown()",1000);
        return;
    }
   </script>
<style>
#form_login{
margin-top:50px;
margin-left:400px;
padding:20px;
width:300px;
border:2px solid;
border-radius:10px; 
border-color:#dedede;
}
</style>
<body onload="countDown()">
<div id="form_login" align="center">
<?php 
//membuat koneksi ke mysql
$connect=mysql_connect($_POST['host'],$_POST['user'],$_POST['pass'])or die (mysql_error());
echo "....Success Connect to server mysql<br/>";

$db=mysql_select_db($_POST['db'])or die (mysql_error());
echo "....database Found<br/>";

//membuat table user dengan user standar
$buat_tbl_user =mysql_query("create table user(id_user int(12) not null primary key AUTO_INCREMENT, username varchar(30) not null, password varchar(32) not null, nama_user varchar(50), domain varchar(30))")or die (mysql_error());

echo "....Success Create Table User<br/>";

//memasukan satu user standar
$tambah_user =mysql_query("insert into user values ('1','admin','password','admin','domain')") or die (mysql_error());
echo "....Success Insert content to user<br/>Username : admin <br/> Password : password <br/> Name : admin <br/> Domain : domain<br/>";

$tbl_article =mysql_query("CREATE TABLE article(id_article int(5) NOT NULL AUTO_INCREMENT, title varchar(255) NOT NULL, content text, tgl datetime NOT NULL,
    PRIMARY KEY (id_article))")or die (mysql_error());
echo"....Berhasil Membuat table Article<br>";
$tambah_article =mysql_query("INSERT INTO `article` (`id_article`, `title`, `tgl`, `content`) VALUES
(1, 'Title Content 1', '2015-11-17 08:04:46', 'Content 1')")or die(mysql_error());
echo"....Success Insert Content to Article<br>";

$tbl_ads=mysql_query("CREATE TABLE IF NOT EXISTS `ads` (
  `id_ads` int(5) NOT NULL AUTO_INCREMENT,
  `ads1` text,
  `ads2` text,
  `ads3` text,
  PRIMARY KEY (`id_ads`)
)")or die(mysql_error());
echo"...success Create table Ads<br>";

$tambah_ads=mysql_query("INSERT INTO ads value (1, 'ads1', 'ads2', 'ads3')")or die(mysql_error());
echo"....success Insert Content to ads";

//membuat file config.php

$file_config = fopen('../config.php', 'w+');
fwrite($file_config, "<?php \r\n");
fwrite($file_config, "\$dbhost='".$_POST['host']."'; \r\n");
fwrite($file_config, "\$dbuser='".$_POST['user']."'; \r\n");
fwrite($file_config, "\$dbpass='".$_POST['pass']."'; \r\n");
fwrite($file_config, "\$db='".$_POST['db']."'; \r\n");
fwrite($file_config, "\$koneksi= mysql_connect(\$dbhost,\$dbuser,\$dbpass); \r\n");
fwrite($file_config, "mysql_select_db(\$db,\$koneksi); \r\n");
fwrite($file_config, "?>");
fclose($file_config);

//memindahkan ke index.php
echo "<h3>Success Create Config.php, Please Delete file Install</h3>
<br/><img src=\"../progress.gif\"><br/>
<span id=\"timer\"> detik </span>
<meta http-equiv=\"refresh\" content=\"10;../admin\">";
?>
</div>
</body>
</html>
avatar maszgalang

@maszgalang

297 Kontribusi 80 Poin


Login untuk gabung berdiskusi