Berikut adalah script php untuk mendeteksi browser yang digunakan oleh client. Letakkan code dibawah ini di paling atas halaman index anda. $useragent=$_SERVER[‘HTTP_USER_AGENT’]; if(preg_match(‘/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm(
Kategori: PHP
Berikut adalah fungsi yang bisa dugunakan untuk mengubah ukuran gambar dengan otomatis menggunakan script PHP. function resize_image($filename, $tmpname, $xmax, $ymax) { $ext = explode(“.”, $filename);
Fungsi dibawah ini bisa dugunakan untuk membuat file zip secara otomatis. /* creates a compressed zip file */ function create_zip($files = array(),$destination = ”,$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in… if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; }
Berikut ini adalah fungsi untuk menghapus folder dengan menggunakan PHP. Jika di dalam folder tsb ada file maka file itu juga akan terhapus. function destroyDir($dir, $virtual = false) {
function list_files($dir) { if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != “.” && $file != “..” && $file != “Thumbs.db”) { echo ‘<a target=”_blank” href=”‘.$dir.$file.’”>’.$file.'</a><br>’.”\n”; } } closedir($handle); } } }
function readable_random_string($length = 6){ $conso=array(“b”,”c”,”d”,”f”,”g”,”h”,”j”,”k”,”l”, “m”,”n”,”p”,”r”,”s”,”t”,”v”,”w”,”x”,”y”,”z”); $vocal=array(“a”,”e”,”i”,”o”,”u”); $password=””; srand ((double)microtime()*1000000); $max = $length/2; for($i=1; $i<=$max; $i++) { $password.=$conso[rand(0,19)]; $password.=$vocal[rand(0,4)]; } return $password; }
Cara membuat halaman download ditunggu 3 detik <?php // if name via get equals ‘download”, show the downloading message. if($_GET[‘name’] == “download”){ echo “Downloading … “; } else { // set refresh to 3 seconds, make the variable name be ‘download’ via the get method; header(“Refresh: 3: url=http://maque.kodingen.com/index.php?name=download”); // show this message echo “You can download in 3 seconds.”; } ?>
Fungsi untuk unzip file menggunakan php = <?php function unzip($location,$newLocation){ if(exec(“unzip $location”,$arr)){ mkdir($newLocation); for($i = 1;$i< count($arr);$i++){ $file = trim(preg_replace(“~inflating: ~”,””,$arr[$i])); copy($location.’/’.$file,$newLocation.’/’.$file); unlink($location.’/’.$file); } return TRUE; }else{ return FALSE; } } include ‘functions.php’; if(unzip(‘zipedfiles/test.zip’,’unziped/myNewZip’)) echo ‘Success!’; else
Script php dibawah ini bisa digunakan untuk meresize ukuran gambar otomatis dan mengubah resolusinya.
Ini adalah tutorial membuat pagination sederhana menggunakan php dan css. Metode pengiriman variabelnya menggunakan $_GET sehingga mudah disesuaikan dengan fungsi php yang telah anda buat.