<?php session_start(); $_SESSION["product_code"] = “2222″; $_SESSION["logged_in"] = “yes”; $enc_session = session_encode(); print “<b>Encoded Session Data:<br/></b>”; print $enc_session . “<br/><br/>”; // Changing session values $_SESSION['product_code'] = “2000″; $_SESSION["logged_in"] = “no”; // printing $_SESSION print “<b>SESSION Array:<br/></b>”; print “<pre>”; print_r($_SESSION); print “</pre>”; session_decode($enc_session); // printing Reloaded $_SESSION print “<b>Reloaded SESSION Array:<br/></b>”; print “<pre>”; print_r($_SESSION); print “</pre>”; ?>
Category: Php
array_diff()
Php’de array’ler arasında farkı, ortak olmayan elemanları listeler. <?php $array1 = array(“a” => “green”, “red”, “blue”, “red”); $array2 = array(“b” => “green”, “yellow”, “red”); $result = array_diff($array1, $array2); print_r($result); ?>
array_intersect()
Php’de array’ler arasında kesişen, ortak olan elemanları listeler. <?php $array1 = array(“a” => “green”, “red”, “blue”); $array2 = array(“b” => “green”, “yellow”, “red”); $result = array_intersect($array1, $array2); print_r($result); ?>
Div Autoload ve Refresh
<script src=”https://code.jquery.com/jquery-2.1.1.min.js” type=”text/javascript”></script> <script> $(document).ready(function(){ setInterval(function(){ $(“#screen”).load(‘banners.php’) }, 2000); }); </script> <?php $bg_array = array(“#CEED9D”,”#ECED9D”,”#EDCF9D”,”#EC9CA7″,”#ED9DD0″,”#EE9DE2″,”#D69DEC”,”#9E9CEC”); $bg = array_rand($bg_array,1); ?> <div class=”banner” style=”background-color:<?php echo $bg_array[$bg];?>;” > <div class=”txt-title”>jQuery DIV Auto Load Refresh</div> <div class=”txt-subtitle”>This Banner auto loads and refreshes every 2 seconds.</div> </div>
TC Kimlik No Kontrol Class’ı
<?php class TCKimlik{ private $tcKimlikNo; public function __construct($tcKimlikNo){ if((int)log($tcKimlikNo,10)!=10){ return false; } $this->tcKimlikNo = $tcKimlikNo; } function strtoupperTR($str){ $str = str_replace(array(‘i’, ‘ı’, ‘ü’, ‘ğ’, ‘ş’, ‘ö’, ‘ç’), array(‘İ’, ‘I’, ‘Ü’, ‘Ğ’, ‘Ş’, ‘Ö’, ‘Ç’), $str); return strtoupper($str); } public function validate(){ $oddSum = 0; $evenSum = 0; if(substr($this->tcKimlikNo,0,1)==0){ return false; } for($i=0;$i<=8;$i++){ if($i%2==0){ $oddSum += […]
Xml Oluşturma
<?php $xml = new DOMDocument(“1.0″, “utf-8″); $root = $xml->createElement(“data”); $xml->appendChild($root); $id = $xml->createElement(“id”); $idText = $xml->createTextNode(’1′); $id->appendChild($idText); $title = $xml->createElement(“title”); $titleText = $xml->createTextNode(‘Test XML’); $title->appendChild($titleText); $book = $xml->createElement(“book”); $book->appendChild($id); $book->appendChild($title); $root->appendChild($book); $xml->formatOutput = true; echo “<xmp>”. $xml->saveXML() .”</xmp>”; $xml->save(“test.xml”) or die(“Error”); ?> <?php $domtree = new DOMDocument(’1.0′, ‘UTF-8′); $xmlRoot = $domtree->createElement(“xml”); $xmlRoot = $domtree->appendChild($xmlRoot); $currentTrack […]
PDO Query Builder Class
class _pdo extends PDO { var $query; private $type; private $values; function __construct($db){ try{ parent::__construct($db['type'].’:host=’.$db['server'].’;dbname=’.$db['db_name'].’;’.$db['charset'],$db['user'],$db['pass'],array(PDO::MYSQL_ATTR_INIT_COMMAND => “SET NAMES ‘utf8′”)); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array(‘_pdo_statement’)); $this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $this->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, true); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){ die(‘Error: ‘. $e->getMessage()); } } public function insert_id(){ return $this->lastInsertId(); } public function find($table, $id){ $columns = $this->column($table); return $this->select($table)->where($columns['Field'] .” = “.$id)->limit(1)->result(); […]
Türkiye Telefon Kodu Veritabanı
Öncelikle buradan telefon kodu bilgilerinin olduğu xml dosyasını bilgisayarınıza indirin. Daha sonra veritabanına telefon kodlarını gireceğiniz tabloyu şöyle hazırlayın: CREATE TABLE `telcode` ( `id` int(11) NOT NULL auto_increment, `city` varchar(25) collate utf8_turkish_ci default NULL, `telCode` varchar(7) collate utf8_turkish_ci default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci; Sonra şu php dosyalarını hazırlayıp, çalıştırmanız yeterli […]
PDO Connect
config.php <?php header(‘Content-Type: text/html; Charset=UTF-8′); date_default_timezone_set(‘Europe/Istanbul’); define(‘MYSQL_HOST’, ‘localhost’); define(‘MYSQL_DB’, ‘test’); define(‘MYSQL_USER’, ‘root’); define(‘MYSQL_PASS’, ”); include ‘db.php’; db.php <?php class DB { static $pdo = null; static $charset = ‘UTF8′; static $last_stmt = null; public static function instance(){ return self::$pdo == null ? self::init() : self::$pdo; } public static function init(){ self::$pdo = new PDO(‘mysql:host=’ . […]
Ayın Kaç Gün Olduğunu Bulmak
echo cal_days_in_month(2,2011);