Irfani Firdausy Live Journal
Random header image... Refresh for more!

Category — PHP

How to Hotlink-protect images using .htaccess

If your running apache server, you can do what you need by configuring your .htaccess file.

You would do something like this to prevent hotlinking of images -

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif¦jpg¦js¦css)$ – [F]

replace mydomain.com with your domain name and only your domain will be allowed to access files appeneded by .gif .jpg .js or .css

you can add other allowed domaine with extra lines e.g. -

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain3.com/.*$ [NC]
RewriteRule \.(gif¦jpg¦js¦css)$ – [F]

October 5, 2009   No Comments

Konversi Angka ke Huruf

Script ini berguna jika kita mau membuat konversi angka ke huruf

<?php
// by irfani.firdausy.com
function ctword($x) {
$x = abs($x);
$number = array(“”, “satu”, “dua”, “tiga”, “empat”, “lima”,
“enam”, “tujuh”, “delapan”, “sembilan”, “sepuluh”, “sebelas”);
$temp = “”;

if ($x <12) {
$temp = ” “. $number[$x];
} else if ($x <20) {
$temp = ctword($x – 10). ” belas”;
} else if ($x <100) {
$temp = ctword($x/10).” puluh”. ctword($x % 10);
} else if ($x <200) {
$temp = ” seratus” . ctword($x – 100);
} else if ($x <1000) {
$temp = ctword($x/100) . ” ratus” . ctword($x % 100);
} else if ($x <2000) {
$temp = ” seribu” . ctword($x – 1000);
} else if ($x <1000000) {
$temp = ctword($x/1000) . ” ribu” . ctword($x % 1000);
} else if ($x <1000000000) {
$temp = ctword($x/1000000) . ” juta” . ctword($x % 1000000);
} else if ($x <1000000000000) {
$temp = ctword($x/1000000000) . ” milyar” . ctword(fmod($x,1000000000));
} else if ($x <1000000000000000) {
$temp = ctword($x/1000000000000) . ” trilyun” . ctword(fmod($x,1000000000000));
}
return $temp;
}
function terbilang($x,$style=4,$strcomma=”,”) {
if($x<0) {
$result = “minus “. trim(ctword($x));
} else {
$arrnum=explode(“$strcomma”,$x);
$arrcount=count($arrnum);
if ($arrcount==1){
$result = trim(ctword($x));
}else if ($arrcount>1){
$result = trim(ctword($arrnum[0])) . ” koma ” . trim(ctword($arrnum[1]));
}
}
switch ($style) {
case 1: //1=uppercase  dan
$result = strtoupper($result);
break;
case 2: //2= lowercase
$result = strtolower($result);
break;
case 3: //3= uppercase on first letter for each word
$result = ucwords($result);
break;
default: //4= uppercase on first letter
$result = ucfirst($result);
break;
}
return $result;
}
?>
<form  method=”post”>
Masukkan Angka <input name=”input” type=”text” id=”input” value=”<?=$_POST['input']?>”/>
<input name=”Show” type=”submit” id=”Show” value=”Show” />
</form>
<? if (isset($_POST['Show']))
{
$input = trim($_POST['input']);

$hasil = terbilang($input,$style=4,$strcomma=”,”);
echo “Terbilang : “. $hasil;
}
?>

December 31, 2008   No Comments

Mengambil beberapa kata dari sebuah kalimat

Terkadang kita ingin mengambil beberapa kata awalan dari sebuah kalimat atau berita.

<?
//programmed by irfani.firdausy.com

function get_kata($kalimat,$batasan)
{
$get_kata = explode(" ",strip_tags($kalimat));
$jumlah = count($get_kata);
if ($jumlah > $batasan )
{
for ($i=0; $i<$batasan; $i++)
{
echo "$get_kata[$i] ";
}

}
else if($jumlah <= $batasan )
{
for ($i=0; $i<$jumlah; $i++)
{
echo "$get_kata[$i] ";
}

}
}

$kalimat= "<p>pagi ini saya bangun jam 5.30 <br> terus sholat, terus mandi terus berangkat ke kantor</p>";
get_kata($kalimat,5);
?>

December 18, 2008   No Comments