Minggu, 10 Januari 2010

PHP : WAKTU & WHILE

WAKTU

$waktu = date ("H:i:s",time());
print "Waktu sekarang adalah $waktu";
?>

WHILE

print "Contoh menggunakan pola while
";
$bila=5;
while ($bila < 20)
{
$bila +=3;
print "$bila
";
}

print "
Contoh menggunakan pola while..endwhile
";
$bila=5;
while ($bila < 20):
print "$bila ";
$bila += 3;
endwhile;
?>

PHP : URUT ARRAY3

$buah = array ("pisang","apel","mangga","durian");

print "Data array sebelum di urutkan adalah :
";
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}

print "Data setelah di urutkan secara ascending
";
asort($buah);
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}

print "Data setelah di urutkan secara descending
";
arsort($buah);
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}
?>


asort(namaarray) untuk ascending dengan index berubah sebaliknya arsort

PHP : URUT ARRAY2

$buah = array("pepaya","apel","mangga","durian");
print "Data array sebelum di urutkan adalah :
";
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}

print "Data setelah di urutkan secara ascending
";
sort($buah);
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}

print "Data setelah di urutkan secara descending
";
rsort($buah);
foreach ($buah as $indeks => $data)
{
print "$indeks : $data
";
}
?>



krsort(namaarray) untuk ascending, snaliknya ksort(nmarray)
sort(namaarray) ascending index tetap senaliknya rsort(namaarray)

PHP : URUT ARAY 1

$teman = array ("2"=>"Meilana", "4"=>"Ali", "3"=>"Zezen", "1" => "Udin");
print "Data aslinya adalah :
";
foreach ($teman as $tampil => $hasil)
{
print "$tampil = $hasil
";
}

print "Pengurutan data secara ascending
";

ksort($teman);
foreach ($teman as $tampil => $hasil)
{
print "$tampil = $hasil
";
}

print "Pengurutan data secara descending :
";
krsort($teman);
foreach ($teman as $tampil => $hasil)
{
print "$tampil = $hasil
";
}
?>

PHP : UPLOAD2




iSimple File Upload Manager by RRWH.com



/* Simple Upload manager
Script Version 0.4, copyright RRWH.com 2004

This script is distributed under the licence conditions on the website http://rrwh.com/scripts.php

This script is a simple interface to allow you to upload files to a configured directory on your server. It will additionally automatically create sub-directories if you want it to. Additionally, It will let you do a directory listing of the base directory or any specified sub-directory.

You only need to modify the $password and $dir variable and ensure that the directory exists on the server and the permission is set to 777

You may want to modify the $types if you wish to allow other file types to be uploaded - Be careful not to allow dangerous files to be uploaded to your server.

*/

$pw = 'fred';

$dir = "D:/xampplite/htdocs/"; //Change this to the correct dir RELATIVE TO WHERE THIS SCRIPT IS, or /full/path/

//MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
$types = array("text/plain","application/pdf","image/png","image/x-png","audio/wav","image/gif","image/jpeg","image/pjpeg","application/x-zip-compressed");

// Nothing to edit below here.

//Function to do a directory listing
/*function scandir($dirstr) {
echo "
\n";

passthru("ls -l -F $dirstr 2>&1 ");
echo "
\n";
}
*/


//Check to determine if the submit button has been pressed
if((isset($_POST['submit'])) and ($_POST['PW'] == $pw)){

//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $_FILES['upload']['name'];
$path = $_POST['subdir'];
// $fullpath = $_SERVER['DOCUMENT_ROOT'].'/nc/';
$fullpath = $_SERVER['DOCUMENT_ROOT'].'/up_download/';
// $fullpath = "D:/xampplite/htdocs.'/up_download/' ";
$fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath)));
$clean_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($new_name) ) ) );

// lets see if we are uploading a file or doing a dir listing
if(isset($_POST['Dir'])){
echo "Directory listing for $fullpath\n";
scandir("$fullpath");
}else{


//Check MIME Type
if ((in_array($_FILES['upload']['type'], $types)) and (!file_exists($fullpath.$clean_name))){

// create a sub-directory if required
if (!is_dir($fullpath)){
mkdir("$fullpath", 0755);
}
//Move file from tmp dir to new location
move_uploaded_file($tmp_name,$fullpath . $clean_name);

echo "$clean_name of {$_FILES['upload']['size']} bytes was uploaded sucessfully to $fullpath
";
echo "mau lihat isinya";
}else{

//Print Error Message
echo "File {$_FILES['upload']['name']} Was Not Uploaded - bad file type or file already exists
";
//Debug
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];

echo "Name: $name
Type: $type
Size: $size
Tmp: $tmp";
}
}
} else {
echo 'Ready to upload your file';
} ?>




Upload Files
Password

Do a directory Listing

File to upload

Subdir to upload to/list directory: " /> (Can be blank) **Directory will be created if it does not exist

Script by RRWH.com




PHP : UPLOAD1

echo mime_content_type('freeundelete.exe') . "\n";
echo mime_content_type('model.zip') . "\n";
//echo mime_content_type('terakhir.php') . "\n";
//echo mime_content_type('alias.eko') . "\n";

//echo $_SERVER['DOCUMENT_ROOT'];

/*if ($submit)
{
$doc_directory="D:/xampplite/htdocs";

$my_file="./up_download/".$userfile_name;
$copy_path=$doc_directory.$my_file;

if (!move_uploaded_file($userfile, $copy_path))
{
print "upload gagal";
}
else
{
print "upload sukses";
}
}

print "
";
print "
";
print "Send this file:
";
print "
";
print "
";
*/
?>

PHP : UPLOAD

$pw = 'eko';
//direktori dimana skrip di jalankan
$dir = "D:/xampplite/htdocs/";
//tipe data yang di perbolehkan untuk upload
$types = array("application/octet-stream","text/plain","application/pdf","image/png","image/x-png","audio/wav","audio/mpeg","image/gif","image/jpeg","image/pjpeg","application/x-zip-compressed");

if((isset($_POST['submit'])) and ($_POST['pass'] == $pw))
{
//Shorten Variables
$tempor = $_FILES['upload']['tmp_name'];
$new_nama =$_FILES['upload']['name'];
$path = $_POST['subdir'];
$fullpath = $_SERVER['DOCUMENT_ROOT'].'/up_download/';
$fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath)));
$nama_baru = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($new_nama) ) ) );

if ((in_array($_FILES['upload']['type'], $types)) and (!file_exists($fullpath.$nama_baru)))
{
move_uploaded_file($tempor,$fullpath . $nama_baru);

print "File $nama_baru {$FILES['upload']['size'] } bytes telah sukses di upload ke $fullpath
";
print "Mau lihat isinya
";
}
else
{
print "File {$_FILES[upload][name]} tidak bisa di upload, mungkin karena salah tipe data atau data telah ada.
";
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];

print "Nama: $name
Type: $type
Size: $size
Tmp: $tmp
";
print "lihat isi folder";
}
}

print "
";
//print "";
print "Password :
";
print "File Upload :
";
print "";
?>

PHP : UBAH STRING

$kata = "abcdefgh";

print "Variabel \$kata = '$kata' di rubah menjadi string baru sebagai berikut :

";
print substr("$kata",2) ."
";
print substr("$kata",3,2) ."
";
print substr("$kata",0,6) ."
";
print substr("$kata",-3,2) ."
";
?>

PHP : UBAH KOLOM

$koneksi=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel="mahasiswa";
$kolom_lama="Alamat";
$kolom_baru="Alamat_lengkap varchar(45) not null";

$sql="ALTER TABLE $tabel CHANGE $kolom_lama $kolom_baru";
$qry=mysql_db_query("contoh",$sql,$koneksi);

if ($qry) {
print "Nama kolom berhasil di rubah";
} else {
print "Nama kolom gagal di rubah";
}
mysql_close();
?>

PHP : TIPE VAR

$angka=78;
$huruf="Belajar PHP dengan cepat";
$bilangan=22.78;

print "Variabel \$angka ";
if (is_int($angka)) {
print "Benar, bertipe integer
";
}
else {
print "Salah, bukan bertipe integer
";
}

print "
";
print "Apakah variabel \$huruf bertipe string?
";
if (is_string($huruf)){
print "Benar, bertipe string
";
}
else{
print "Salah, bukan bertipe string";
}

print "
";
print "Apakah variabel \$bilangan bertipe boolean?
";
if (is_bool($bilangan)){
print "Benar, variabel ini bertipe boolean
";
}
else {
print "Salah, bukan bertipe boolean tapi tipe ". gettype($bilangan);
}
?>

fungsi mendeteksi type variabel:

is_string(namavariabel) = apakakah variabel string
is_int(namavariabel) = ? var integer
is_numerical(namavariabel) = ? var numerik/amgka
is_double(namavariabel) = ? var double
is_array(namavariabel) = ? var array
is_bool(namavariabel) = ? var boolean

fungsi gettype(nama_variavel)= untuk mengetahui tipe var yg dgunakan

PHP : TIPE ARRAY

$campur = array ("25", "Selamat", "34.5");

print "$campur[0]
"; //tipe data integer
print "$campur[1]
"; //tipe data string
print "$campur[2]"; //tipe data double
?>

PHP : TESTKU1

$status=0;
if (isset($Cookieku) && ($Cookieku == "cooki"))
{
$status=1;
if (!isset($cek)) {
setcookie("Cookieku", "cooki");
header("Location: $PHP_SELF?cek=1");
exit;
}
}
print " Browser Anda : ";
printf ('%s
',
$status ? "000000" : "FF0000",
$status ? "mendukung Cookie" : "tidak mendukung Cookie!");
?>

PHP : TESTKU

ob_start();

if (isset($_GET["logout"])) {
setcookie("cookieku", "");
header("location: cookie.php?isloggedout");
}

if ($_GET["passed"] == 1) {
$status = 1;
} else {
if (isset($_COOKIE["cookieku"]) && $_COOKIE["cookieku"] == 'cooki') {
$status = 1;
} else {
$status = 0;
}
}

// if cookieku belum diset
if (!isset($_GET["isloggedout"])) {
if (!isset($_COOKIE["cookieku"])) {

setcookie("cookieku", "cooki");
header("location: cookie.php?passed=1");
}
}

echo $status == 1 ? "Browser Anda mendukung cookie
Nilai cookie : ". $_COOKIE["cookieku"] ."
hapus cookie" : "Browser anda tidak support cookie";

?>

PHP : TEST

// Define variable to prevent hacking
define('IN_CB',true);

// Including all required classes
require('class/index.php');
require('class/FColor.php');
require('class/BarCode.php');
require('class/FDrawing.php');

// including the barcode technology
include('class/code39.barcode.php');

// Creating some Color (arguments are R, G, B)
$color_black = new FColor(0,0,0);
$color_white = new FColor(255,255,255);

/* Here is the list of the arguments:
1 - Thickness
2 - Color of bars
3 - Color of spaces
4 - Resolution
5 - Text
6 - Text Font (0-5) */
$code_generated = new code39(30,$color_black,$color_white,1,'HELLO',2);

/* Here is the list of the arguments
1 - Width
2 - Height
3 - Filename (empty : display on screen)
4 - Background color */
$drawing = new FDrawing(1024,1024,'',$color_white);
$drawing->init(); // You must call this method to initialize the image
$drawing->add_barcode($code_generated);
$drawing->draw_all();
$im = $drawing->get_im();

// Next line create the little picture, the barcode is being copied inside
$im2 = imagecreate($code_generated->lastX,$code_generated->lastY);
imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY);
$drawing->set_im($im2);

// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');

// Draw (or save) the image into PNG format.
$drawing->finish(IMG_FORMAT_PNG);
?>

PHP : TEST PANJANG

$cekpanjang=strlen($tele);

if ((($cekpanjang >=7) && ($cekpanjang <=14)) && (is_numeric($cekpanjang)))
{
print "input OK";
}
else
{
print "Data tidak valid";
}
?>

PHP : TEST DB1

$conn=mysql_connect("localhost","eko","eko") or die("Koneksi gagal");
if ($conn) {
print "Koneksi ok";
} else {
print "Koneksi gagal";
}
?>

PHP : TEST COOKIE 1

//include_once("buatcookie.php"):
if (isset($test)) {
print "Cookies yang masih aktif adalah $test";
} else {
print "Nilai Cookies sudah kosong";
}
?>

PHP : TEST COOKIE

/*
$tes_cookie="tes browser";
if ($er != $tes_cookie)
{
setcookie("cookieku",$tes_cookie);
header("Location:$PHP_SELF?$tes_cookie);
}

if ($cookieku==$tes_cookie)
{
print "browser Anda mendukung";
}
else
{
print "browser anda tidak mendukung";
}
*/

$status=0;
if (isset($cookieku) && ($cookieku == "cooki")) { $status = 1;
if (!isset($cek)) {
setcookie("cookieku", "cooki");
header("location: $PHP_SELF?cek=1");
exit;
}
}

printf ('%s
',
$status ? "000000" : "FF0000",
$status ? "Browser Anda mendukung cookie" : "Browser anda tidak support cookie");

?>

PHP : TEST BARCODE

// Define variable to prevent hacking
define('IN_CB',true);

// Including all required classes
require('class/index.php');
require('class/FColor.php');
require('class/BarCode.php');
require('class/FDrawing.php');

// including the barcode technology
include('class/code39.barcode.php');

// Creating some Color (arguments are R, G, B)
$color_black = new FColor(0,0,0);
$color_white = new FColor(255,255,255);

/* Here is the list of the arguments:
1 - Thickness
2 - Color of bars
3 - Color of spaces
4 - Resolution
5 - Text
6 - Text Font (0-5) */
$code_generated = new code39(30,$color_black,$color_white,1,'HELLO',2);

/* Here is the list of the arguments
1 - Width
2 - Height
3 - Filename (empty : display on screen)
4 - Background color */
$drawing = new FDrawing(1024,1024,'',$color_white);
$drawing->init(); // You must call this method to initialize the image
$drawing->add_barcode($code_generated);
$drawing->draw_all();
$im = $drawing->get_im();

// Next line create the little picture, the barcode is being copied inside
$im2 = imagecreate($code_generated->lastX,$code_generated->lastY);
imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY);
$drawing->set_im($im2);

// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');

// Draw (or save) the image into PNG format.
$drawing->finish(IMG_FORMAT_PNG);
?>

PHP : TERNARI

$a=1;
$b=2;
$c=$a < $b;

print "Nilai \$a adalah $a
";
print "Nilai \$b adalah $b

";
print "\$c = \$a < \$b
";
print "Hasil operasi diatas adalah
";

if ($c)
{
print "True atau 1

";
}
else
{
print "False atau 0

";
}

print "Jika menggunakan operator ternary yaitu :
";
print "\$c =((\$a < \$b)) ? 'True atau 1' : 'False atau 0' "."
";
print "Hasilnya adalah : ";
print $c =(($a < $b)) ? 'True atau 1' : 'False atau 0';
?>

PHP : TERAKHIR MODIF

$terakhir = date("d-F-Y. H:i:s a", getlastmod());
print "Terakhir kali di modifikasi adalah pada tanggal $terakhir ";
?>

PHP : TEXT GAMBAR

header("Content-Type:image/jpeg");
$background=@imagecreate(100,100);
$kuning=imagecolorallocate($background,250,250,300);
$hitam=imagecolorallocate($background,0,0,0);
imagestring($background,5,10,40,"Tips PHP",$hitam);
imageJPEG($background);
imagedestroy($background);
?>

PHP : TANGGAL FORMAT1

mysql_connect("localhost","","") or die ("Koneksi gagal...");
mysql_select_db("contoh");
$sql=mysql_query("select date_format(tanggal,'%d-%m-%Y') as tanggal from waktu");
if ($baris=mysql_fetch_array($sql))
{
print "Tanggal sekarang adalah : $baris[tanggal]";
}
else
{
print "Data tidak ditemukan...";
}
?>

PHP : TANGGAL FORMAT

$tanggal=date("d-m-Y H:i:s",time());
print "Tanggal dan waktu sekarang adalah $tanggal";
?>

PHP : TANGGAL

$tanggal=date("Ymd",time());
print "Tanggal hari ini adalah $tanggal";
?>

PHP : TAMPIL DATA1

$p= 12345;
$s= -12345;
$d= 12/5;
$f= 162.67 - 12;

printf ("%d
" ,$p);
printf ("%d
",$s);
printf ("%f
",$d);
printf ("%d
",$f);
?>

PHP : TAMPIL DATA

include_once("konek_db.php");
//$connect=mysql_connect("localhost","priyo","priyo") or die ("Koneksi gagal");
$sql="SELECT NIK,Nama,Alamat,Phone,date_format(Tglmasuk,'%d-%m-%Y') as tanggal,Bagian,Jabatan,Keterangan from karyawan";
$qry=mysql_db_query("karyawan",$sql,$connect);

print "print "
NIK";
print "
Nama";
print "
Alamat";
print "
Phone";
print "
Tanggal Masuk";
print "
Bagian";
print "
Jabatan";
print "
Keterangan";
while ($row=mysql_fetch_row($qry))
{
print "
$row[0]";
print "
$row[1]";
print "
$row[2]";
print "
$row[3]";
print "
$row[4]";
print "
$row[5]";
print "
$row[6]";
print "
$row[7]";
print "
edit";
print "
hapus";
}
print "
";
?>

PHP : TAMPIL KOLOM

$conn=mysql_connect("localhost","","") or die ("Koneksi gagal");

$database="contoh";
$tabel="mahasiswa";

mysql_select_db($database,$conn) or die ("Database $database tidak dapat dibuka");
$sql=mysql_query("select * from $tabel", $conn);

print "Kolom yang ada pada tabel $tabel adalah :
";
print mysql_field_name($sql, 0) ."
";
print mysql_field_name($sql, 1) ."
";
print mysql_field_name($sql, 2) ."
";
print mysql_field_name($sql, 3) ."
";
print mysql_field_name($sql, 4) ."
";
?>

PHP : TAMBAH KOLOM1

$koneksi=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel = "mahasiswa";
$kolom1 = "id int not null FIRST";
$kolom2 = "email varchar(20) not null";

$sql="ALTER TABLE $tabel ADD $kolom1";
$qry=mysql_db_query("contoh",$sql,$koneksi);

$sql1="ALTER TABLE $tabel ADD $kolom2 AFTER telepon";
$qry1=mysql_db_query("contoh",$sql1,$koneksi);

if (($qry) && ($qry1)) {
print "Kolom-kolom baru telah berhasil di tambahkan";
} else {
print "Kolom baru gagal di tambahkan";
}
mysql_close();
?>

PHP : TAMBAH KOLOM

$koneksi=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel = "mahasiswa";
$kolom_baru = "kelulusan varchar(15) not null";

$sql="ALTER TABLE $tabel ADD $kolom_baru";
$qry=mysql_db_query("contoh",$sql,$koneksi);
if ($qry) {
print "Kolom baru telah berhasil di tambahkan";
} else {
print "Kolom baru gagal di tambahkan";
}
mysql_close();
?>

PHP : TABEL WARNA

$conn=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel="mahasiswa";

$sql="select * from $tabel";
$qry=mysql_db_query("contoh",$sql,$conn);

$jumlah=mysql_num_fields($qry);

print " Jumlah kolom pada tabel $tabel adalah $jumlah
";
print "Atributnya adalah sebagai berikut :
";

//Disusun dalam bentuk tabel
print "";
print "";
for ($i=0; $i<$jumlah; $i++)
{
print "";
}
print "";

print "";
for ($i=0; $i<$jumlah; $i++)
{
print "";
}
print "";
print "
";
print mysql_field_name($qry, $i);
print "
";
print mysql_field_type($qry, $i) ."
";
print "(" .mysql_field_len($qry, $i). ")";
print "
";
mysql_close();
?>

PHP : TAMPIL ATRIBUT

$conn=mysql_connect("localhost","","") or die ("Koneksi gagal");
$tabel="mahasiswa";

$sql="select * from $tabel";
$qry=mysql_db_query("contoh",$sql,$conn);

$jumlah=mysql_num_fields($qry);

print " Jumlah kolom pada tabel $tabel adalah $jumlah
";
print "Atributnya adalah sebagai berikut :
";

//Disusun dalam bentuk tabel
print "";
print "";
for ($i=0; $i<$jumlah; $i++)
{
print "";
}
print "";

print "";
for ($i=0; $i<$jumlah; $i++)
{
print "";
}
print "";
print "
";
print mysql_field_name($qry, $i);
print "
";
print mysql_field_type($qry, $i) ."
";
print "(" .mysql_field_len($qry, $i). ")";
print "
";
mysql_close();
?>

PHP : TAMBAH ARRAY

$asli = array ("satu","dua","tiga");

array_push ($asli,"empat","lima");

while (list($nilai,$hasil) = each($asli))
{
print "$nilai : $hasil
";
}
?>

PHP : SWITCH

$a=15;
print "Nilai \$a adalah $a
";

switch ($a)
{
case '$a = 20':
{
print "Nilai variabel a sama dengan 20";
}
break;

case '$a < 20':
{
print "Nilai variabel a lebih kecil dari 20";
}
break;

default:
{
print "Nilai variabel a lebih besar dari 20";
}
break;
}
?>

php : string

$a = "Selamat";
$b = $a . " Datang";
print "$b
";

$a = "Selamat";
$a .= " Datang";
print "$a
";
?>

. adalah merangkaikan kata argumen kiri dan kanan
.= adalah argumen kanan dgn yg dikiri

php : spasi

$kata = " Program PHP ";
print "Kata '$kata' dengan spasi di depan dan di belakang
";
$hilang1 = ltrim($kata);
print "Di hilangkan spasi di depan menjadi :
";
print "'$hilang1'

";
$hilang2 = rtrim($kata);
print "Di hilangkan spasi di belakang menjadi :
";
print "'$hilang2'

";
$hilang3 = trim($kata);
print "Di hilangkan spasi di depan dan di belakang menjadi :
";
print "'$hilang3'
";
?>

PHP : SPACE

// tanda /home;/usr dan /www adalah direktori untuk Linux
$systempartitions = array("/", "/home","/usr", "/www");
foreach ($systempartitions as $partition)
{
//1 MB = 1048576 bytes
//1 MB != 1000000 bytes
$totalSpace = disk_total_space($partition) / 1048576;
$usedSpace = $totalSpace - disk_free_space($partition) / 1048576;
echo "Partisi: $partition (Total Space: $totalSpace MB. Yang digunakan: $usedSpace MB.)
";
}
print "
";
print "Total space yang ada pada drive C adalah : ".disk_total_space("C:")." byte
";
print "Total space yang ada pada drive D adalah : ".disk_total_space("D:")." byte
";

print "Space yang masih ada pada drive C adalah : ".disk_free_space("C:")." byte
";
print "Space yang masih ada pada drive D adalah : ".disk_free_space("D:")." byte
";
?>

PHP : SIFAT FILE1

function outputFileTestInfo( $f ){
if ( ! file_exists( $f ) ){
print "$f tidak ada
";
return;
} else {
print "$f di rubah pada ".date( "D d M Y g:i A", filectime( $f ) )."
";
print "$f di modifikasi ".date( "D d M Y g:i A", filemtime( $f ) )."
";
print "$f di akses pada ".date( "D d M Y g:i A", fileatime( $f ) )."
";
}
}

$file = "file.txt";
outputFileTestInfo( $file );
?>

PHP : SIFAT FILE

function InfoFile( $file1 ){
if (! file_exists( $file1 ) ){
print "$file1 tidak ada
";
return;
} else {
print "$file1 adalah ".(is_file( $file1 )?"":"not ")."sebuah file
";
print "$file1 adalah file ".(is_executable( $file1 )?"":"not ")."executable / di eksekusi
";
print "$file1 adalah file ".(is_readable( $file1 )?"":"not ")."readable / di baca
";
print "$file1 adalah file ".(is_writable( $file1 )?"":"not ")."writable / di tulis
";
print "$file1 adalah file ".(is_dir( $file1 )?"":"not ")." sebuah direktori
";
}
}

$file = "file.txt";
InfoFile( $file );
?>

PHP : SEKOLAH

include_once("barmaker.php");
$b = new Bar();

$b->AddValue("Semester 1", array("4.0", "4000"));
$b->AddValue("Semester 2", array("3.5", "3000"));
$b->AddValue("Semester 3", array("3.7", "2750"));
$b->AddValue("Semester 4", array("3.9", "3500"));

$b->SetTitle("My school days");
$b-SetTitleColor(255, 0, 0); //red

$b->SetAxesColor(100, 100, 100);

$b->SetBGColor(255, 255, 255);

$b->Spit("jpg");


?>

PHP : REKENING

print "";
print "Masukkan nomor rekening Anda :
";
print "
";
print "";
print "";
?>

PHP : PROSES EDIT

include_once("konek_db.php");
$sql="UPDATE karyawan SET Nama='$nama',
Alamat='$alam',
Phone='$phon',
Tglmasuk='$tgl',
Bagian='$bagi',
Jabatan='$jaba',
Keterangan='$kete'
where NIK='$nik'";
$qry=mysql_db_query("karyawan",$sql,$connect);

if ($qry)
{
print "Data telah berhasil di update
";
print "lihat data";
}
else
{
print "Data gagal di update";
}
?>

PHP : CARI PROSES

include_once("konek_db.php");
$sql="SELECT NIK,Nama,Alamat,Phone,date_format(Tglmasuk,'%d-%m-%Y') as tanggal,Bagian,Jabatan,Keterangan from karyawan where $pilihan LIKE '%$cari%'";
$qry=mysql_db_query("karyawan",$sql,$connect);

print "";
print "
NIK";
print "
Nama";
print "
Alamat";
print "
Phone";
print "
Tanggal Masuk";
print "
Bagian";
print "
Jabatan";
print "
Keterangan";
while ($row=mysql_fetch_row($qry))
{
print "
$row[0]";
print "
$row[1]";
print "
$row[2]";
print "
$row[3]";
print "
$row[4]";
print "
$row[5]";
print "
$row[6]";
print "
$row[7]";
}
?>

PHP : PROSES CARI

include_once("konek_db.php");
$sql="SELECT NIK,Nama,Alamat,Phone,date_format(Tglmasuk,'%d-%m-%Y') as tanggal,Bagian,Jabatan,Keterangan from karyawan where $pilihan LIKE '%$cari%'";
$qry=mysql_db_query("karyawan",$sql,$connect);

print "";
print "
NIK";
print "
Nama";
print "
Alamat";
print "
Phone";
print "
Tanggal Masuk";
print "
Bagian";
print "
Jabatan";
print "
Keterangan";
while ($row=mysql_fetch_row($qry))
{
print "
$row[0]";
print "
$row[1]";
print "
$row[2]";
print "
$row[3]";
print "
$row[4]";
print "
$row[5]";
print "
$row[6]";
print "
$row[7]";
}
?>

PHP : PROSES

if ($nama=='eko' && $pass=='priyo') {
print "Anda telah berhasil login";
} else {
print "Data Anda salah, silahkan login kembali";
}
?>

PHP : POSISI

$kalimat = "Pemrograman PHP";
$karakter= "m";
$posisi = strpos($kalimat, $karakter);

print "Karakter '$karakter' berada pada posisi ke-$posisi dalam kalimat '$kalimat'
";
?>

PHP : PORT

ini_set("max_execution_time",120);

$Start = 0;
$Stop = 1024;

$target = "www.yahoo.co.id";

$range =range($Start, $Stop);
echo "

Hasil scan untuk alamat $target

";

foreach ($range as $port) {
$result = @fsockopen($target, $port,$errno,$errstr,1);
if ($result)
echo "

Yang terbuka pada port $port

";
}
?>

PHP : PISAH STRING

$kalimat = "Ibukota Indonesia adalah Jakarta";
$pecah = strtok ($kalimat," ");
while ($pecah)
{
print "$pecah
";
$pecah=strtok(" ");
}
?>

PHP : PIE

print "";
?>

PHP : PERBANDINGAN

$a=12;
$b=13;

print "Variabel \$a = $a dan \$b = $b

";

printf ("Nilai \$a == \$b adalah %d
",$a==$b);
== akan bernilai b jika kedua nilai sama, dan s jika tdk sama

printf ("Nilai \$a <> \$b adalah %d
",$a<>$b);
akan b jika keduanya tdk sama, / sebaliknya

printf ("Nilai \$a > \$b adalah %d
",$a > $b);
akan b jika sbelah kiri besar, / sbaliknya

printf ("Nilai \$a < \$b adalah %d
",$a < $b);
akan b jika sbelah kiri kecil, / sbaliknya

printf ("Nilai \$a <= \$b adalah %d
",$a <= $b);
akan b jika sbelah kiri kecil/=, / sbaliknya

printf ("Nilai \$a >= \$b adalah %d

",$a >= $b);
akan b jika sbelah kiri besar/=, / sbaliknya

print "Keterangan:
";
print "Nilai 1 berarti Benar / True
";
print "Nilai 0 berarti Salah / False ";
?>

PHP : PEMBUAT PIE

class Pie
{
var $imageWidth = 400;
var $imageHeight = 300;
var $bgR = 255;
var $bgG = 255;
var $bgB = 255;
var $title = "Pie Chart - 123ashish.com";


function create($varDesc, $varValues)
{
Header("Content-type: image/png");
$image = ImageCreate($this->imageWidth, $this->imageHeight);

$bgcolor = ImageColorAllocate($image,
$this->bgR, $this->bgG, $this->bgB);

$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
ImageFill($image, 0, 0, $bgcolor);

$num = 0;
foreach($varDesc as $v)
{
$r = rand (0, 255);
$g = rand (0, 255);
$b = rand (0, 255);

$sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b);
$num++;
}

// now $num has the number of elements

// draw the box
ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black);
ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black);
ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black);
ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black);

$total = 0;
for ($x = 0; $x < $num; $x++)
{
$total += $varValues[$x];
}

// convert each slice into corresponding percentage of 360-degree circle
for ($x = 0; $x < $num; $x++)
{
$angles[$x] = ($varValues[$x] / $total) * 360;
}


for($x = 0; $x < $num; $x++)
{
// calculate and draw arc corresponding to each slice
ImageArc($image,
$this->imageWidth/4,
$this->imageHeight/2,
$this->imageWidth/3,
$this->imageHeight/3,
$angle,
($angle + $angles[$x]), $sliceColors[$x]);

$angle = $angle + $angles[$x];

$x1 = round($this->imageWidth/4 + ($this->imageWidth/3 * cos($angle*pi()/180)) / 2);
$y1 = round($this->imageHeight/2 + ($this->imageHeight/3 * sin($angle*pi()/180)) / 2);

// demarcate slice with another line
ImageLine($image,
$this->imageWidth/4,
$this->imageHeight/2,
$x1, $y1, $sliceColors[$x]);
}

// fill in the arcs
$angle = 0;
for($x = 0; $x < $num; $x++)
{
$x1 = round($this->imageWidth/4 +
($this->imageWidth/3 * cos(($angle + $angles[$x] / 2)*pi()/180)) / 4);
$y1 = round($this->imageHeight/2 +
($this->imageHeight/3 * sin(($angle + $angles[$x] / 2)*pi()/180)) / 4);

ImageFill($image, $x1, $y1, $sliceColors[$x]);

$angle = $angle + $angles[$x];
}


// put the desc strings
ImageString($image, 5, $this->imageWidth/2, 60, "Legend", $black);
for($x = 0; $x < $num; $x++)
{
$fl = sprintf("%.2f", $varValues[$x] * 100 / $total);
$str = $varDesc[$x]." (".$fl."%)";
ImageString($image, 3 , $this->imageWidth/2, ($x + 5) * 20, $str, $sliceColors[$x]);
}

// put the title
ImageString($image, 5, 20, 20, $this->title, $black);

ImagePng($image);
ImageDestroy($image);
}
}

$pie = new Pie;

if(isset($width))
{
$pie->imageWidth = $width;
}

if(isset($height))
{
$pie->imageHeight = $height;
}

if(isset($title))
{
$pie->title = $title;
}

$varDesc = explode(",", $desc);
$varValues = explode(",", $values);

$pie->create($varDesc, $varValues);
?>

PHP : PASWORD

function generatePassword ($length = 15)
{
//inisialisasi password kosong
$password = "";

//daftar karakter-karakter yang di perbolehkan
$possible = "0123456789bcdfghjkmnpqrstvwxyz";

//buat awal penghitung
$i = 0;

//tambahkan karakter acak sampai $length terpenuhi
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

//jika karakter sudah ada, tidak boleh digunakan lagi
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}
$pass=generatePassword();
print "Password Anda adalah $pass";
?>

PHP : PANJANG

print "
";
print "Masukkan nomor telepon Anda :
";
print "";
print "";
print "
";
?>

PHP : PANGGIL

print "";
print "";
print "
";
print "

Isi Web

";
print "
";
include_once("terakhir.php");
print "";
print "";
?>

PHP : OOP

/*class lingkaran {
var $jari_jari;
var $diameter;
var $luas;
var $keliling;

function hitung_lingkaran($r)
{
$this->jari_jari=$r;
$this->luas = 3.14*($r*$r);
$this->diameter=2*$r;
$this->keliling=2*3.14*$r;
}
}

$luas_lingkaran = new lingkaran;
$luas_lingkaran->hitung_lingkaran(3);

echo "jari-jari lingkaran : $luas_lingkaran->jari_jari
";
echo "keliling lingkaran : $luas_lingkaran->keliling";

*/




/* db.class.php
A simple database manipulation class by Salman AS, salmanas@programmer.net.
ChangeLog: 02/14/2001 Started.
02/26/2001 Query Method added.
*/class DB {
var $Connection;
var $DBHost=”localhost”;
var $DBUser=”root”;
var $DBPass=”";
var $DBName;
var $DBRecSet;

// Constructor for this class
function DB ($db_host, $db_user, $db_pass, $db_name) {
$this->DBHost = $db_host;
$this->DBUser = $db_user;
$this->DBPass = $db_pass;
$this->DBName = $db_name;

if (!$this->Open()) echo “Error occure on openning connection or database. Period.”;
}

// Open database server connection
function Open () {
if (!($ServerConn = @mysql_pconnect($this->DBHost, $this->DBUser, $this->DBPass))) {
return 0;
} else {
if (!($this->Connection = @mysql_select_db($this->DBName, $ServerConn)))
return 0;
else
return 1;
}
}

function Query ($sql) {
if (empty($sql)) echo “No SQL command given. Period.”;
if ($this->DBRecSet=@mysql_query(addslashes($sql)))
return $this->DBRecSet;
else
return 0;
}
}
?>

PHP : OBJEK

class persegi
{
var $panjang;
var $lebar;
var $luas;
var $keliling;

function persegi_panjang($p,$l)
{
$this->panjang = $p;
$this->lebar = $l;
$this->keliling = 2*($p+$l);
$this->luas = $p*$l;
}
}

$persegi_panjang1 = new persegi;
$persegi_panjang1->persegi_panjang(6,4);

print "Nilai panjang adalah : $persegi_panjang1->panjang
";
print "Nilai lebar adalah : $persegi_panjang1->lebar
";
print "Keliling persegi panjang adalah : $persegi_panjang1->keliling
";
print "Luas persegi panjang adalah : $persegi_panjang1->luas
";
?>

PHP : NUMERIK

print "
";
print "Masukkan Data :
";
print "Nama :
";
print "Umur :
";
print "Telepon :
";
print "";
print "
";

if ($submit)
{
if (!is_numeric($nama))
{
print "Data Anda benar";
}
elseif (is_numeric($umur))
{
print "Data Anda benar";
}
elseif (is_numeric($telp))
{
print "Data Anda benar";
}
else
{
print "Anda memasukkan tipe data yang salah";
}
}
?>

PHP : CEK IP

print "Nomor IP Addres Anda adalah ";
print "".$HTTP_SERVER_VARS["REMOTE_ADDR"]."";
?>

PHP : NIL VAR

$nilai1=12; //tipe data integer
$nilai2=8.99; //tipe data float atau double
$nilai3= "Tes nilai variabel string"; //tipe data string

print "Tipe data integer : $nilai1
";
print "Tipe data double : $nilai2
";
print "Tipe data string : $nilai3 ";
?>

$namavariabel=nilai data

PHP : NILAI VAR

$angka=98;
$huruf="Selamat Datang";
$bilangan=34.7;

echo "Variabel \$angka adalah ";
echo var_dump($angka) ."
";

echo "Variabel \$huruf adalah ";
echo var_dump($huruf) ."
";

echo "Variabel \$bilangan adalah ";
echo var_dump($bilangan) ."
";
?>


untuk mengetahui nilai 7 tipe suatu variabel
format fungsi

var_dump(namavariabel)

PHP : MULTI TABEL

$conn=mysql_connect("localhost","","");
$tabel1=coba1;
$tabel2=coba2;

$sql="create table $tabel1 (id int not null primary key, nama varchar(35))";
$qry=mysql_db_query("contoh",$sql,$conn);
if ($qry)
{
print "tabel1 sukses terbentuk
";
}

$sql1="create table $tabel2 (id int not null primary key, nama_mahasiswa varchar(40))";
$qry1=mysql_db_query("contoh",$sql1,$conn);
if ($qry1)
{
print "tabel2 sukses terbentuk";
}

mysql_close();
?>

PHP : MULTI INPUT

$conn=mysql_connect("localhost","","") or die ("Koneksi gagal");
$sql="insert into mahasiswa values
('12354','Leni Nur Astuti','Bandung','081523652210','2.78'),
('12356','Bagus Pratama','Bali','08562123255','3.11'),
('12359','Yeni Kurniawan','Sumedang','08560012331','3.02'),
('12365','Bondan Rahmat','Yogyakarta','08110002525','2.99')";
$input=mysql_db_query("contoh",$sql,$conn);

if ($input) {
print "Data telah berhasil di masukkan";
} else {
print "Data tidak dapat di masukkan";
}
?>

PHP : MULTI ARRAY

$pola = array (array (Klub => "Persik", Kota => "Kediri"),
array (Klub => "PSIS", Kota => "Semarang"),
array (Klub => "Arema", Kota => "Malang"));

print "Klub Liga Indonesia 2007
";
foreach ($pola as $nilai)
{
foreach ($nilai as $daftar=>$hasil)
{
print "$daftar : $hasil
";
}
print "
";
}
?>

PHP : METODE

print "
";
print "Masukkan Nama :
";
print "Masukkan Password :
";
print "";
print "
";
?>

PHP : INPUT DATA

include_once("konek_db.php");
$sql="insert into karyawan (NIK, Nama, Alamat, Phone, Tglmasuk, Bagian,
Jabatan, Keterangan) values ('$nik','$nama','$alam','$phon','$tgl','$bagi','$jaba','$kete')";
$qry=mysql_db_query("karyawan",$sql,$connect);

if ($qry) {
print "Data telah masuk
";
print "masukkan data lagi
";
print "tampilkan data";
}
else {
print "Data tidak masuk";
}
?>

PHP : INPUT DATA KE ACCES


$koneksi=odbc_connect("mahasiswa","","");
$sql="insert into tbl_mahasiswa (NIM,Nama) values ('$nim','$nama')";

if (odbc_do($koneksi,$sql))
{
print "Data Anda sudah tersimpan";
}
else
{
print "Data gagal di simpan";
}
odbc_close($koneksi);
?>

PHP : LOGIKA

$data1=true;
$data2=true;
$data3=false;

print "\$data1 = true
";
print "\$data2 = true
";
print "\$data3 = false

";

$hasil1= $data1 && $data2;
&&=akan 1 jika keduanya 1, selain itu 0

print "\$hasil1 = \$data1 && \$data2 "."
";
printf ("Nilai \$data1 && \$data2 adalah : %d

",$hasil1);

$hasil2= $data1 || $data3;
||=akan 1 jika salah satunya 1, jika keduanya 0 maka 0

print "\$hasil2 = \$data1 || \$data3 "."
";
printf ("Nilai \$data1 || \$data3 adalah : %d

",$hasil2);

$hasil3= $data2 xor $data3;
xor= 1 jika keduanya sama, slain itu 0

print "\$hasil3 = \$data2 xor \$data3 "."
";
printf ("Nilai \$data1 xor \$data3 adalah : %d

",$hasil3);

$hasil4= !$data2;
negasi/ingkaran

print "\$hasil4 = !\$data2 "."
";
printf ("Nilai !\$data2 : %d",$hasil4);
?>

php : lingkaran

header("Content-Type:image/jpeg");
$background=@imagecreate(100,100);
$kuning=imagecolorallocate($background,250,250,300);
$hitam=imagecolorallocate($background,0,0,0);
imagearc($background,50,50,50,50,0,360,$hitam);
imageJPEG($background);
imagedestroy($background);
?>

PHP : COPY FILE

print "
";
print "Copy File
";
print "
";
print "Tujuan :";
print "
";
print "";
print "
";

if ($submit)
{
copy($file,"$tujuan://".$file_name);
print "File $file_name telah sukses di copy ke drive $tujuan
";
}
?>

PHP : KONFERSI DETIK

function sec2hms ($sec, $padHours=false)
{
$hms = "";
//mendapatkan nilai integer dari jam
$hours = intval(intval($sec) / 3600);

// ditambahkan ke variabel $hms
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';

//mendapatkan nilai integer dari menit
$minutes = intval(($sec / 60) % 60);

// ditambahkan ke variabel $hms
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';

//mendapatkan nilai integer dari menit
$seconds = intval($sec % 60);

// ditambahkan ke variabel $hms
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);

//keluarkan output
return $hms;
}
print "
";
print "Masukkan nilai detik yang akan di konversi
";
print "
";
print "";
print "
";

if ($submit)
{
$waktu=sec2hms($detik);
print "Nilai $detik detik sama dengan $waktu";
}
?>

PHP : KONSTANTA1

require ("konstanta.php");
print "Jari-jari = $jarijari ". GantiBaris;
print "Nilai phi ".phi . GantiBaris;
print "Luas = $luas". GantiBaris;
print Selesai;
?>

formula memanggil nilai konstanta yg ada difile lain

require("nama file.php"); atau
include("nama file.php");

PHP : KONSTANTA

define ("phi",3.14);
define ("Hasilnya","Luas Lingkaran");
define ("GantiBaris", "
");
define ("Selesai", "thanks");

$jarijari=7;
$luas=phi*$jarijari*$jarijari;

//printf ("Jari-jari lingkaran adalah $jarijari
");
//printf ("Nilai phi = %s
",phi);
//printf (" %s = $keliling",Hasilnya);
?>

konstanta = variabel
konstanta=tetap
variabel=berubah2

define("nama konstnta","nilai konstanta");

PHP : KONEKSI 1

$koneksi=mysql_connect("localhost","","");
if ($koneksi)
{
print "Koneksi ke server berhasil";
}
else
{
die ("Koneksi ke server gagal");
}
?>

PHP : KONEKSI


$konek=odbc_connect("mahasiswa","","");
if (!$konek)
{
die ("Koneksi database gagal");
}
else
{
print "Koneksi berhasil";
}
odbc_close($konek);




//memasukkan data ke database Access
/*
print "
";
print "";
print "
NIM:";
print "
Nama:";
print "
";
print "
";
print "
";
*/
?>

PHP : KONEKSI DB

$connect=mysql_connect("localhost","priyo","priyo") or die ("Koneksi gagal");

mysql_close();
?>

PHP : KONEKSI DB

$connect=mysql_connect("localhost","priyo","priyo") or die ("Koneksi gagal");

mysql_close();
?>

PHP : KAPITAL HURUF

$kalimat = "belajar pemrograman web dengan PHP";
print "Kalimat awal adalah '$kalimat'

";
$ubah1 = ucfirst($kalimat);
print "Setelah dirubah kapital huruf awalnya menjadi :
";
print "$ubah1

";
$ubah2 = ucwords($kalimat);
print "Setelah dirubah kapital per kata menjadi :
";
print "$ubah2
";
?>

PHP : KAPITAL

$kalimat = "Juara Liga Indonesia 2006 adalah Persik Kediri";
print "Kalimat awal adalah :
";
print "$kalimat

";
$ubah1 = strtoupper($kalimat);
print "Kalimat diatas dirubah menjadi huruf besar semua menjadi :
";
print "$ubah1

";
$ubah2 = strtolower($kalimat);
print "Kalimat diatas dirubah menjadi huruf kecil semua menjadi :
";
print "$ubah2
";
?>

PHP : JUMLAH SUB

$kalimat = "PHP merupakan bahasa pemrograman web dinamis. Bahasa PHP cukup mudah di pelajari, dan PHP free";
$jumlah=substr_count($kalimat, "PHP");
print "Kalimat berikut ini
'$kalimat'

";
print "Jumlah kata 'PHP' dalam kalimat di atas adalah : $jumlah ";
?>

PHP : JUMLAH

$kata2 = array("ex", "te", "xt","ek");
$lihat = "text text text text text text text text";
foreach($kata2 as $kw) {
echo "Kata $kw terlihat ".substr_count($lihat,$kw)." kali.
";
}
?>

PHP : ISI FILE

$nama_file = "file.txt";
$buka_file = fopen ($nama_file, "r");
while (!feof($buka_file))
{
$data1=fgets($buka_file, 50);
print "$data1";
}
fclose($buka_file);
?>

PHP : ISIS DATA

print "
";
print "Masukkan Nama :
";
print "Masukkan Umur :
";
print "Masukkan Email:
";
print "";
print "
";
?>

PHP : INFO FILE

print "Informasi File
";
print "Nama File : $namafile_name
";
print "Ukuran File : $namafile_size
";
print "Tipe File : $namafile_type
";
?>

PHP : INDEX ARRAY

$pemain[Persik]="Budi Sudarsono";
$pemain[Persita]="Firman Utina";
$pemain[PSIS]="Maman Abdurahman";
$pemain[Persib]="Zaenal Arif";

print "Pemain terbaik Liga Indonesia 2006 adalah $pemain[PSIS]";
?>

PHP : IF SARANG

$a=12;
$b=32;
$c=120;

print "Nilai \$a = $a, \$b = $b dan \$c = $c
";

if ($a<$b)
{
if ($b<$c)
{
print "Variabel c mempunyai nilai paling besar";
}
}
else
{
print "Variabel c bukan yang terbesar";
}
?>

PHP : IF ELSE

$a = 2;
$b = 15;

print "\$a = $a dan \$b = $b
";

if ($a > $b)
{
print "Nilai a lebih besar dari nilai b";
}
else
{
print "Nilai a lebih kecil dari nilai b";
}
?>


bentuk bersarang

PHP : HITUNG KAR

$kalimat = "Belajar PHP";
$jumlah=strlen($kalimat);
print "variabel string \$kalimat = $kalimat
";
print "Kalimat '$kalimat' diatas jumlah karakternya adalah $jumlah ";
?>


strlem(nm varstring)

PHP : HAPUS FILE

$nama_file="C:/tes1.php";
if (unlink($nama_file))
{
print "File sudah berhasil di hapus";
}
else
{
print "File belum bisa di hapus";
}
?>

PHP : HAPUS DIR

$folder="D:\folder_eko";
if (rmdir($folder)) {
print "Folder telah sukses di hapus";
}
else {
print "Folder gagal di hapus";
}
?>

PHP: HAPUS DATA

include_once("konek_db.php");
$sql="delete from karyawan where NIK='$nik'";
$qry=mysql_db_query("karyawan",$sql,$connect);
print "Data sudah berhasil di hapus
";
print "lihat data";
?>

PHP : HAPUSS COKIE

setcookie("test","");
?>



if (isset($test)) {
print "Nilai cookies yang aktif adalah $test";
} else {
print "Nilai cookies telah kosong";
}
?>


PHP : HAPUS SESS

session_start();
session_unset();
session_destroy();
print "Session sudah terhapus semua";
?>