<body onload="setInterval('window.location.reload()', 120000);">
Category: Coding
how i can close popup window in php …?
echo “<script type=\”text/javascript\” charset=\”utf-8\”>window.self.close()</script>”;
PHP hapus files pada suatu direktori
<?php
// Specify the target directory and add forward slash
$dir = “myFolder/”;
// Open the directory
$dirHandle = opendir($dir);
// Loop over all of the files in the folder
while ($file = readdir($dirHandle)) {
// If $file is NOT a directory remove it
if(!is_dir($file)) {
unlink (“$dir”.”$file”); // unlink() deletes the files
}
}
// Close the directory
closedir($dirHandle);
?>
Mengambil 2 digits terakhir thn ini
var twoDigitsCurrentYear = parseInt(new Date().getFullYear().toString().substr(2,2));
Enkripsi Script PHP Agar Source Code Web PHP Tidak Bisa Dibaca, Menggunakan Fungsi Eval dan Encode 64
Enkripsi Script PHP Agar Source Code Web PHP Tidak Bisa Dibaca, Menggunakan Fungsi Evel dan Encode 64 cukup mudah dilakukan akan tetapi hasilnya cukup efektif untuk menyembunyikan kode program PHP sehingga sulit dibaca atau diedit oleh orang awam.
Tetapi sebenarnya cara ini bukan benar-benar mengamankan Script PHP akan tetapi hanya membuat bingung atau istilahnya obfuscate PHP script sehingga susah untuk dipecahkan walaupun oleh orang yang paham (programmer) dan bahkan kemungkinan besar tidak akan bisa dibaca atau dipecahkan oleh orang awam.
Dalam contoh program yang penulis buat terdiri dari 4 buah file, dengan urutan sebagai berikut :
1. decoded.php (file PHP asli yang dapat dibaca)
2. php-encoder.php (script PHP untuk mengenkripsi script yang ada di file decoded.php menjadi file encoded.php.
3. encoded.php (file PHP yang sudah dienkripsi sehingga tidak dapat dibaca tetapi masih dapat dijalankan secara sempurna.
4. php-decoder.php (script PHP untuk mengembalikan script terenkripsi yang ada pada file encoded.php menjadi file script PHP yang dapat dibaca kembali menjadi file decoded.php.
Jadi urutan pengetesannya kira-kira sebagai berikut :
decoded.php -> php-encoder.php -> encoded.php -> php-decoder.php -> decoded.php -> dst.
Misalnya kita buat contoh file script PHP pada decoded.php sebagai berikut :
decoded.php :
<?php echo date(“Y-m-d”).” Hello World”; ?>
Jika dijalankan dengan cara memanggil halaman web tersebut dengan URL http://localhost/php-encoder/decoded.php akan tampil sebagai berikut :
Kemudian kita buat program PHP dengan nama php-encoder.php untuk mengenkripsi script php yang ada pada file decoded.php.
php-encoder.php :
<?php /*$php_code = ‘<?php echo date(“Y-m-d”).” Hello World”; ?>’;*/ $php_code = file_get_contents(“decoded.php”); //$_F=__FILE__; $_X=’?>’.$php_code; $_X=strtr($_X,’aouie123456′,’123456aouie’); $_X=base64_encode($_X); //$_R=ereg_replace(‘__FILE__’,”‘”.$_F.”‘”,$_X); $result = “<?php \$_F=__FILE__;\$_X='”.$_X.”‘; eval(base64_decode(‘JF9YPWJhc2U2NF9kZWNvZGUoJF9YKTskX1g9c3RydHIoJF9YLC cxMjM0NTZhb3VpZScsJ2FvdWllMTIzNDU2Jyk7JF9SPWVyZWdfcmVwbGFjZSgnX19GS UxFX18nLCInIi4kX0YuIiciLCRfWCk7ZXZhbCgkX1IpOyRfUj0wOyRfWD0wOw==’));?>”; file_put_contents(“encoded.php”, $result); echo str_replace(‘<‘,’<’,str_replace(‘>’,’>’,$result)); ?>
Jika halaman php-encoder.php dijalankan dengan cara memanggil http://localhost/php-encoder/php-encoder.php. Hasilnya akan didapatkan file baru dengan nama encoded.php :
encoded.php :
<?php $_F=__FILE__;$_X=’Pz48P3BocA0KNWNoMiBkMXQ1KCJZLW0tZCIpLiIgSDVsbDIgVzJybGQiOw0KPz4=’; eval(base64_decode(‘JF9YPWJhc2U2NF9kZWNvZGUoJF9YKTskX1g9c3RydHIoJF9YLC cxMjM0NTZhb3VpZScsJ2FvdWllMTIzNDU2Jyk7JF9SPWVyZWdfcmVwbGFjZSgnX19GS UxFX18nLCInIi4kX0YuIiciLCRfWCk7ZXZhbCgkX1IpOyRfUj0wOyRfWD0wOw==’));?>
Kenyataanya jika halaman encoded.php yang sudah terenkripsi dan tidak dapat dibaca ini dijalankan dengan cara menanggil http://localhost/php-encoder/encoded.php, ternyata hasilnya persis seperti ketika menjalankan halaman decoded.php.
Untuk mengembalikan file yang terlah terenkripsi menjadi script PHP semula, kita buat file php-decoder.php untuk mengubah file encoded.php kembali menjadi file decoded.php yang mampu dibaca kembali.
php-decoder.php
<?php $_F=__FILE__; $encode = file_get_contents(“encoded.php”); $_X = substr($encode, strpos($encode, “='”) + 2, strpos($encode, “‘;”) – strpos($encode, “='”) – 2); //$_X=’Pz48P3BocA0KNWNoMiAiSDVsbDIgVzJybGQiOw0KPz4=’; $_X=base64_decode($_X); $_X=strtr($_X,’123456aouie’,’aouie123456′); $_R=ereg_replace(‘__FILE__’,”‘”.$_F.”‘”,$_X); $_R=substr($_R, 2, strlen($_R)-2); file_put_contents(“decoded.php”, $_R); echo str_replace(‘<‘,’<’,str_replace(‘>’,’>’,$_R)); ?>
Ketika dijalankan dengan memanggil URL http://localhost/php-encoder/php-decoder.php maka akan dihasilkan file decoded.php kembali dengan isi persis seperti semula.
decoded.php
<?php echo date(“Y-m-d”).” Hello World”; ?>
Source Info: http://cariprogram.blogspot.com/2014/03/enkripsi-script-php-agar-source-code-php-tidak-bisa-dibaca.html
4 digits numbering
$num = 9;
$paddedNum = sprintf(“%04d”, $num);
echo $paddedNum; // prints 0009
MySQL SUM() function dengan GROUP BY
MySQL SUM() function retrieves the sum value of an expression which has undergone a grouping operation by GROUP BY clause.
SELECT cate_id,SUM(total_cost)
FROM purchase
GROUP BY cate_id;
Easy Numbers and Currency Formatting Plugin – autoNumeric
autoNumeric is an useful jQuery plugin for international currency formatting as well as numbers formatting. It supports almost all the major international numeric formats and currency signs used in Europe, North and South America, Asia and India.
http://www.jqueryscript.net/other/Easy-Numbers-Currency-Formatting-Plugin-autoNumeric.html
Split nilai pada JavaScript
Berikut salah satu contoh penggunaan split untuk memisahkan sebuah nilai string ke dalam sebuah variabele array. Setelah itu, nilai dimasukkan kedalam input form berdasarkan id-nya.
function fill(Value)
{
var splits = Value.split(‘-‘);
$(‘#nomor’).val(splits[0]);
$(‘#nama_pasien’).val(splits[1]);}
Add and Remove ListBox Items in JavaScript
Step 1: For this, we will first use some controls like TextBox (txtValue) to add the value in the ListBox, ListBox (lstValue) and an Add and Delete Button as in the following:
<input name=”txtValue” type=”text” />
<input type=”button” name=”add” value=”Add” onclick=”addValue();” />
<select name=”lstValue” multiple>
<option value=”empty”></select>
<input type=”button” name=”delete” value=”Delete” onclick=”deleteValue();” />
Step 2: Now we will write the code for adding the items in the ListBox like this:
<script language=”javascript” type=”text/javascript”>
var i = 0;
function addValue() {
var v = document.form1.txtValue.value;
// get the TextBox Value and assign it into the variable
AddOpt = new Option(v, v);
document.form1.lstValue.options[i++] = AddOpt;
return true;
}
</script>
Source: http://www.c-sharpcorner.com/UploadFile/mahakgupta/add-and-remove-listbox-items-in-javascript/




