Codeigniter Dinamik Drowdown Listesi Helper

/helper/dropdown_helper.php <?php if(!defined(‘BASEPATH’)) exit(‘No direct script access allowed’); function listData($table, $name, $value, $orderBy=’ASC’){ $items = array(); $CI =& get_instance(); if($orderBy){ $CI->db->order_by($value,$orderBy); } $query = $CI->db->select(“$name,$value”)->from($table)->get(); if ($query->num_rows() > 0){ foreach($query->result() as $data) { $items[$data->$name] = $data->$value; } $query->free_result(); return $items; } } /config/autoload.php $this->load->helper(‘form’,dropdown’); /controllers/test.php <?php class Test extends CI_Controller { public function index() { […]

Read More

URL’den Domain Adını Çekme

function getDomainName($url){ if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE){ return false; } $urlChenks = parse_url($url); return $urlChenks['scheme'].’://’.$urlChenks['host']; } Örnek Kullanım: echo getDomainName(‘https://www.emretalu.net/test_url/’);

Read More

Dinamik Yıl Drowdown Listesi

function yearDropdownMenu($start_year, $end_year = null, $id=’year_select’, $selected=null) { $end_year = is_null($end_year) ? date(‘Y’) : $end_year; $selected = is_null($selected) ? date(‘Y’) : $selected; $r = range($start_year, $end_year); $select = ‘<select name=”‘.$id.’” id=”‘.$id.’”>’; foreach($r as $year){ $select .= “<option value=\”$year\””; $select .= ($year==$selected) ? ‘ selected=”selected”‘ : ”; $select .= “>$year</option>\n”; } $select .= ‘</select>’; return $select; […]

Read More

PHP Validation

E-Mail Validation $email = ‘testuser@gmail.com’; if (filter_var($email, FILTER_VALIDATE_EMAIL)) { echo “This ($email) email address is considered valid.”; } else { echo “This ($email_a) is valid Email.”; } URL Validation $url = “http://www.test.com”; if(filter_var($url, FILTER_VALIDATE_URL)) { echo “$url is valid URL”; } else { echo “$url is invalid Valid URL”; } IP Validation $ip = ’127.0.0.1′; […]

Read More

Array İçindeki Multiple Elemanları Bulma

function search_in_array($search, $source) { return (count(array_intersect($search, $source)) == count($search)); } Örnek; $search = array(11,44,55); $source = array(22,55,66,11,77,88,99,44); var_dump(search_in_array($search, $source)); $search = array(11,44,55); $source = array(22,55,66,11,77,88,99,44); var_dump(search_in_array($search, $source));

Read More

Random String Oluşturma

function random_string($length){ $chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890″; $string = ”; for($i=0;$i<$length; $i++){ $string .= $chars[rand(0,strlen($chars)-1)]; } return $string; }

Read More

PDO Database Class

config.php <?php define(“DB_HOST”, “localhost”); define(“DB_USER”, “root”); define(“DB_PASS”, “”); define(“DB_NAME”, “test”); database.class.php <?php class Database{ private $host = DB_HOST; private $user = DB_USER; private $pass = DB_PASS; private $dbname = DB_NAME; private $dbh; private $error; private $stmt; public function __construct(){ $dsn = ‘mysql:host=’ . $this->host . ‘;dbname=’ . $this->dbname . ‘;charset=utf8′; $options = array( PDO::ATTR_PERSISTENT => […]

Read More

Ziyaretçinin IP Adresini Almak

function getClientIP() { if (isset($_SERVER['HTTP_CLIENT_IP'])){ $ipaddress = $_SERVER['HTTP_CLIENT_IP']; }else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; }else if(isset($_SERVER['HTTP_X_FORWARDED'])){ $ipaddress = $_SERVER['HTTP_X_FORWARDED']; }else if(isset($_SERVER['HTTP_FORWARDED_FOR'])){ $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; }else if(isset($_SERVER['HTTP_FORWARDED'])){ $ipaddress = $_SERVER['HTTP_FORWARDED']; }else if(isset($_SERVER['REMOTE_ADDR'])){ $ipaddress = $_SERVER['REMOTE_ADDR']; }else{ $ipaddress = ‘UNKNOWN’; } return $ipaddress; }

Read More