<?php if (! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); function link($q) { $q = str_replace(”,’ ’,$q); $q = str_replace(‘!’,’!’,$q); $q = str_replace(“‘”,’"’,$q); $q = str_replace(‘#’,’#’,$q); $q = str_replace(‘$’,’$’,$q); $q = str_replace(‘%’,’%’,$q); $q = str_replace(‘&’,’&’,$q); $q = str_replace(“‘”,’'’,$q); $q = str_replace(‘(‘,’(’,$q); $q = str_replace(‘)’,’)’,$q); $q = str_replace(‘*’,’*’,$q); $q = str_replace(‘+’,’+’,$q); $q = str_replace(‘,’,’,’,$q); $q = str_replace(‘-’,’-’,$q); $q […]
Category: Php
Linux Kullanıcı Hesabı İşlemleri
<?php $groupname = “”; $username = “”; $password = “”; $home = “”; // /var/www/$username function createUser($groupname, $username, $home, $password){ exec(“mkdir ” . $home); exec(“useradd ” . $username); exec(“groupadd ” . $groupname); exec(“passwd ” . $username); exec(“gpasswd -a ” . $username . “” . $groupname); exec(“chown –R ” . $username . “” . $home); exec(“chgrp […]
Random Parola Oluşturucu
<?php if (! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); function pass_generator($amount) { $keyset = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″; $randkey = “”; for ($i=0; $i<$amount; $i++){ $randkey .= substr($keyset, rand(0, strlen($keyset)-1), 1); } return $randkey; } ?>
Domain Ping
<?php $ping = exec(“ping 127.0.0.1″); print($ping); ?> Eğer, exec komutu çalışmazsa şu yöntemi de kullanabilirsiniz: <?php function pingDomain($domain, $port, $timeout, &$message){ $file = fsockopen ($domain, $port, $errno, $errstr, $timeout); $status = 0; $message = $message == null ? $message = array() : $message; if (!$file){ $status = -1; $m = “ping $domain:$port -> status:$status (errno:$errno […]
Associative Array Sum
<?php $data = array( 0 => array( ‘event’ => ‘Conference’, ‘budget’ => 3700, ), 1 => array( ‘event’ => ‘Conference’, ‘budget’ => 500, ), 2 => array( ‘event’ => ‘Showroom’, ‘budget’ => 1000, ), 3 => array( ‘event’ => ‘Mission Chez client’, ‘budget’ => 2000, ), 4 => array( ‘event’ => ‘Séminaire’, ‘budget’ => 700, […]
Timezone
<?php function get_time($zone_key){ $tz = new DateTimeZone($zone_key); $data = new DateTime(date(“Y-m-d H:i:s”)); $data->setTimezone($tz); //$data = new DateTime(date(“Y-m-d 00:00:00″),$tz); return $data->format(“r”); } if (!empty($_POST)){ echo get_time($_POST["timezone"]); } $zones = timezone_identifiers_list(); ?> <form action=”” method=”post”> <select name=”timezone”> <?php foreach ($zones as $key) { ?> <option value=”<?=$key;?>”><?=$key;?></option> <?php } ?> </select> <input type=”submit” value=”Select” /> </form>
cURL Nedir?
En basit anlamda cURL PHP’de daha sayfa işlenirken sayfaya veri çekmeye yarar. Örnek olarak bunu bot veya webservis yapımında kullanabiliriz. Tabi bu özelliği kullanabilmek için php.ini dosyanızda php_curl.php özelliği aktif olmak zorunda. Kod Örneği: $temp = array(“a”=>1, “b”=>2); $postdata = http_build_query($temp); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); //POST Metoduyla verileri gönder curl_setopt($ch, CURLOPT_HEADER, false); //Serverdan […]
Sef Link Fonksiyonu
function permalink($string) { $find = array(‘Ç’, ‘Ş’, ‘Ğ’, ‘Ü’, ‘İ’, ‘Ö’, ‘ç’, ‘ş’, ‘ğ’, ‘ü’, ‘ö’, ‘ı’, ‘+’, ‘#’); $replace = array(‘c’, ‘s’, ‘g’, ‘u’, ‘i’, ‘o’, ‘c’, ‘s’, ‘g’, ‘u’, ‘o’, ‘i’, ‘plus’, ‘sharp’); $string = strtolower(str_replace($find, $replace, $string)); $string = preg_replace(“@[^A-Za-z0-9\-_\.\+]@i”, ‘ ‘, $string); $string = trim(preg_replace(‘/\s+/’, ‘ ‘, $string)); $string = str_replace(‘ […]
Tükçe Karakter Düzeltme Fonksiyonu
function duzelt($metin) { $metin = trim($metin); $metin = strtolower($metin); $bul = array(“ı”,”Å?”,”ü”,”ç”,”ö”,”Ä?”,”ÅŸ”,”Ç”,”Ä°”,”ÄŸ”,”Åz”,”Ö”,”Ãœ”,”ı”,”Å?”,”ç”,”ö”,”Ä?”,”ÅŸ”,”Ç”,”Ä°”,”ÄŸ”,”Åz”,”Ö”,”Ãœ”,”ü”,”ÄŸ”); $duzelt = array(“ı”,”ş”,”ü”,”ç”,”ö”,”ğ”,”ş”,”Ç”,”i”,”ğ”,”Ş”,”Ö”,”Ü”,”ı”, “ş”, “ç”, “ö”, “ğ”, “ş”, “Ç”, “i”, “ğ”, “Ş”, “Ö”, “Ü”, “ü”, “ğ”); $metin = str_replace($bul, $duzelt, $metin ); return $metin; }
MySql Yedek Alma Dosyası
define(‘DB_HOST’, ‘localhost’); define(‘DB_NAME’, ‘veritabani_adi’); define(‘DB_USER’, ‘veritabani_kullaniciadi’); define(‘DB_PASSWORD’, ‘parola’); define(‘BACKUP_SAVE_TO’, ‘yedek_alinacak_dizin’); $time = time(); $day = date(‘j’, $time); if ($day == 1) { $date = date(‘Y-m-d’, $time); } else { $date = $day; } $backupFile = BACKUP_SAVE_TO . ‘/’ . DB_NAME . ‘_’ . $date . ‘.gz’; if (file_exists($backupFile)) { unlink($backupFile); } $command = ‘mysqldump –opt […]