PHP header(‘Cache-Control: no-cache, no-store, must-revalidate’); // HTTP 1.1. header(‘Pragma: no-cache’); // HTTP 1.0. header(‘Expires: 0′); // Proxies. Java Servlet response.setHeader(“Cache-Control”, “no-cache, no-store, must-revalidate”); // HTTP 1.1. response.setHeader(“Pragma”, “no-cache”); // HTTP 1.0. response.setDateHeader(“Expires”, 0); // Proxies. ASP.NET Response.AppendHeader(“Cache-Control”, “no-cache, no-store, must-revalidate”); // HTTP 1.1. Response.AppendHeader(“Pragma”, “no-cache”); // HTTP 1.0. Response.AppendHeader(“Expires”, “0″); // Proxies. ASP Response.addHeader “Cache-Control”, […]
Category: Php
Sayfa Yönlendirme Fonksiyonu
function redirect($time = 0, $page){ echo “<meta http-equiv=\”refresh\” content=\”$time;url=$page\”>\n”; } redirect(2, “index.php”); redirect(“www.google.com”);
Çok Boyutlu Array İçindeki İkinci Derece Key Bilgilerini Almak
function getL2Keys($array){ $result = array(); foreach($array as $sub) { $result = array_merge($result, $sub); } return array_keys($result); }
Xampp apc Eklentisi
Öncelikle buraya tıklayarak apc eklenti dosyalarını indirin. Daha sonra php.ini dosyasını açıp şu kodları ekleyin: extension=php_apc.dll [APC] apc.enabled = 1 ;istege bagli olarak asagidakiler de eklenebilir apc.shm_segments = 1 apc.shm_size = 64 apc.max_file_size = 10M apc.stat = 1
Boş Satırları Temizleme
$string = preg_replace(“/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/”, “\n”, $string);
Seçilen Zamanın Belirtilen Aralıkta Olup Olmadığını Hesaplama
<?php $start = strtotime(’02:00:00′); $end = strtotime(’16:00:00′); //$now = strtotime(date(“H:i:s”)); $now = strtotime(’08:00:00′); if($start < $end){ // regular day if($now > $start && $now < $end){ echo “Gece”; }else{ echo “Gunduz”; } }else{ // rotate day if($now > $start || $now < $end){ // early night echo “Gece”; }else{ echo “Gunduz”; } } ?>
Mysql Batch Insert
mysql fonksiyonları ile: $sql = array(); foreach( $data as $row ) { $sql[] = ‘(“‘.mysql_real_escape_string($row['text']).’”, ‘.$row['user_id'].’)’; } mysql_query(‘INSERT INTO table (text, user) VALUES ‘.implode(‘,’, $sql)); mysqli fonksiyonları ile: $query = mysqli_prepare(“INSERT INTO table (text, user) VALUES(?,?,?)”); foreach($JSON_data as $key => $value) { $query->bind_param($value["text"], $value["user_id"]); $query->execute(); }
Image Resize
<form name=”frmImageResize” action=”” method=”post” enctype=”multipart/form-data”> <input type=”file” name=”myImage” /> <input type=”submit” name=”submit” value=”Submit” /> </form> <?php if(isset($_POST["submit"])) { if(is_array($_FILES)) { $file = $_FILES['myImage']['tmp_name']; $source_properties = getimagesize($file); $image_type = $source_properties[2]; if($image_type == IMAGETYPE_JPEG) { $image_resource_id = imagecreatefromjpeg($file); $target_layer = fn_resize($image_resource_id,$source_properties[0],$source_properties[1]); imagejpeg($target_layer,$_FILES['myImage']['name'] . “_thump.jpg”); } elseif($image_type == IMAGETYPE_GIF) { $image_resource_id = imagecreatefromgif($file); $target_layer = fn_resize($image_resource_id,$source_properties[0],$source_properties[1]); imagegif($target_layer,$_FILES['myImage']['name'] . […]
XML Parser
<?php $xmlDocument = ‘ <?xml version=”1.0″?> <toys> <toy code=”10001″> <name>Ben 10 Watch</name> <type>Battery Toys</type> </toy> <toy code=”10002″> <name>Angry Birds Gun</name> <type>Mechanical Toys</type> </toy> </toys>’; $line_number = 0; function onStart($parser,$name,$attributes) { global $line_number; if($line_number != xml_get_current_line_number($parser)) { $line_number = xml_get_current_line_number($parser) . “: “; $output = “<br/>” . $line_number . ” \t<” . $name . “>”; } […]
XML Reader
<?php $xmlDocument = ‘ <?xml version=”1.0″?> <toys> <toy code=”10001″> <name>Ben 10 Watch</name> <type>Battery Toys</type> </toy> <toy code=”10002″> <name>Angry Birds Gun</name> <type>Mechanical Toys</type> </toy> </toys>’; $xml = new XMLReader(); $xml->XML($xmlDocument); while( $xml->read() ) { if($xml->name == “toy”) { print “ID:” . $xml->getAttribute(“code”) . “<br/>”; print $xml->readInnerXML() . “<br/>”; $xml->next(); } } ?>