Php : Cookie, Cookie Kullanımı, Cookie Silme

Cookie  nedir?
Cookie , genellikle bir kullanıcıyı tanımlamak için kullanılır. Cookie , sunucunun kullanıcının bilgisayarına yerleştirdiği küçük bir dosyadır. Aynı bilgisayar bir tarayıcıyla bir sayfa istediğinde, Cookie  de gönderir. PHP ile Cookie  değerlerini oluşturabilir ve alabilirsiniz.

Bir Cookie Nasıl Oluşturulur?
Setcookie (ad, değer, süre sonu, yol, etki alanı);

Örnek
Setcookie (“kullanıcı”, “Ozan Yıldırım”, zaman () + 3600);

Cookie Değeri Nasıl Alınır?
PHP $ _COOKIE değişkeni Cookiedeğeri almak için kullanılır.

Örnek –
Echo $ _COOKIE [“kullanıcı”];
// Tüm Cookie görüntülemenin bir yolu
Print_r ($ _ COOKIE);

Bir Cookie Nasıl Silinir?
Bir tanımlama bilgisini silerken, son kullanma tarihinin geçmişte olduğunu onaylamalısınız.
// son kullanma tarihini bir saat önceye ayarla
Setcookie (“kullanıcı”, “”, zaman () – 3600);

 

PHP’den Çerez Desteği Kontrolü

<? Php
If (! Isset ($ _ GET [‘testcookie’]))
{
Setcookie (“testcookie”, “test değeri”);
Başlık (“Yer: {$ _SERVER [” PHP_SELF “]}? Testcookie = 1”);
çıkış;
}
Başka
{
If (isset ($ _ COOKIE [‘testcookie’]))
{
Setcookie (“testcookie”);
Echo “Çerezleriniz etkinleştirildi”;
}
Başka
{
Echo “Çerezleri desteklemiyor!”;
}
}
? >

Tüm çerez değerlerini okuma

<? Php
Foreach ($ _COOKIE olarak $ cookie_name => $ cookie_value)
{
print “$ cookie_name = $ cookie_value
“;
}
? >

Çerez ile giriş yapma

<? Php
$ Auth = $ _COOKIE [‘auth’];
header( “Cache-Control:no-cache” );
If (! $ Auth == “tamam”)
{
header(“Location:login.php” );
exit();
}
? >

Çerez değeri yazdırma

<? Php
print ‘Hello, ‘ . $_COOKIE[‘userid’];
?>

Çerez değerini okuma

<? Php
If (isset ($ _ COOKIE [‘flavor’]))
{
print “You ate a {$_COOKIE[‘flavor’]} cookie.”;
}
?>

Php Class : Php Binary to Text

  < ? 
     function bin2text($bin_str) 
     { 
       $text_str = ''; 
       $chars = explode("\n", chunk_split(str_replace("\n", '', $bin_str), 8)); 
       $_I = count($chars); 
       for($i = 0; $i < $_I; $text_str .= chr(bindec($chars[$i])), $i ); 
       return $text_str; 
     } 
     function text2bin($txt_str) 
     { 
       $len = strlen($txt_str); 
       $bin = ''; 
       for($i = 0; $i < $len; $i ) 
       { 
         $bin .= strlen(decbin(ord($txt_str[$i]))) < 8 ? str_pad(decbin(ord($txt_str[$i])), 8, 0, STR_PAD_LEFT) : decbin(ord($txt_str[$i])); 
       } 
       return $bin; 
     } 
     print text2bin('How are you gentlements?'); 
  ? >

Php Class : Php Dizi Ekleme (Array Insertion)

Php Class : Php Dizi Ekleme (Array Insertion)

class arrayAll 
  { 
     var $startError = 'Warning:Check your input parameters'; 
     var $endError = ''; 
     function Insert($array = '', $position = '' , $elements= '') 
     { 
       if ($position == '' || $array == '' || $elements == '' || $position < 1 || $position > count($array)+1) 
       { 
         echo $this->startError . "insert".$this->endError; 
       } 
       else 
       { 
         $left = array_slice ($array, 0, $position+1); 
         $right = array_slice ($array, $position+1,count($array)); 
         for($i=1; $i< COUNT($elements) ; $i++) 
         { 
           $insert[$i] .= $elements[$i] ; 
         } 
         $array = array_merge ($left, $insert, $right); 
         // echo " Left Count : " . COUNT($left) . "
\n"; 
         // echo " Insert Count : " . COUNT($insert) . "
\n"; 
         // echo " Right Count : " . COUNT($right) . "
\n"; 
         unset($left, $right, $insert); 
       } 
       unset ($position, $elements); 
       return $array ; 
     } 
  }

Php Class : Formdaki gizli (hidden) veriyi almak için php sınıfı

A class to put get and post variables in hidden form

< ? php 
     class c_HiddenVars 
     { 
       function display($a) 
       { 
         $c = Count($a); 
         for ($i = 0, Reset($a); $i < $c; $i++, Next($a)) 
         { 
           $k = Key($a); $v = $a[$k]; 
           if (is_array($v)) 
           { 
             $vc = Count($v); 
             for (Reset($v), $vi = 0; $vi < $vc; $vi++, Next($v)) 
             { 
               $vk = Key($v); 
               echo "< input type=hidden name=\"$k\[$vk\]\" value=\"".htmlspecialchars($v [$vk]). "\">\n"; 
             } 
           } 
           else 
           { 
             echo "< input type=hidden name=\"$k\" value=\"".htmlspecialchars($v). "\">\n"; 
           } 
         } 
       } 
   
       function get() 
       { 
         global $HTTP_GET_VARS; 
         if (is_array($HTTP_GET_VARS)) 
         { 
           $this->display 
           ($HTTP_GET_VARS); 
         } 
       } 
       function post() 
       { 
         global $HTTP_POST_VARS; 
         if (is_array($HTTP_POST_VARS)) 
         { 
           $this->display 
           ($HTTP_POST_VARS); 
         } 
       } 
       function all() 
       { 
         $this->get(); 
         $this->post(); 
       } 
     }; 
   ?>

Php & MySql (Veritabanı) İşlemleri

  < ? php 
     $db = "newdb"; 
     //connect to server with username and password 
     $connection = @mysql_connect ("localhost","root", "") or die (mysql_error()); 
     //connect to database 
     $result = @mysql_create_db($db, $connection) or die(mysql_error()); 
     if ($result) 
     { 
       echo"Database has been created!"; 
     } 
  ?>

Kimliği doğrula: Veritabanı tabanlı (Authenticate user: Database based)

  < ? php 
     function authenticate_user() 
     { 
       header('WWW-Authenticate: Basic realm="Secret Stash"'); 
       header("HTTP/1.0 401 Unauthorized"); 
       exit; 
     } 
     if (! isset($_SERVER['PHP_AUTH_USER'])) 
     { 
       authenticate_user(); 
     } 
     else 
     { 
       mysql_pconnect("localhost","authenticator","secret") or die("Can't connect to database server!"); 
       mysql_select_db("abcd") or die("Can't select authentication database!"); 
       $query = "SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')"; 
       $result = mysql_query($query); 
       // If nothing was found, reprompt the user for the login information. 
       if (mysql_num_rows($result) == 0) 
       { 
         authenticate_user(); 
       } 
     } 
  ? >

Veritabanı sorgusundan veri alın (Get data from database query)

   < ? php 
     $cnx = mysql_connect('mysql153.secureserver.net','abcd','password'); 
     mysql_select_db('abcd'); 
     $employees = @mysql_query('SELECT ID, FirstName FROM Employee'); 
     if (!$employees) 
     { 
       die('Error retrieving employees from database!'. 
       'Error: ' . mysql_error() ); 
     } 
     while ($employee = mysql_fetch_array($employees)) 
     { 
       $id = $employee['ID']; 
       $name = htmlspecialchars($author['Name']); 
       echo("$name "); 
  v     echo("$id"); 
     } 
   ? >

Veritabanı Bağlantısı-MySQL ile bağlantı kurma (Database Connection-establish a connection with MySQL)

•Connect database connections

  < ? php 
     $host="mysql153.secureserver.net"; 
     $uname="abcd"; 
     $pass="password"; 
     $connection= mysql_connect ($host, $uname, $pass); 
     if (! $connection) 
     { 
       die ("A connection to the Server could not be established!"); 
     } 
     else 
     { 
       echo "User root logged into to MySQL server ",$host," successfully."; 
     } 
  ?> 

•Close database connections

  < ? php 
     @mysql_connect("mysql153.secureserver.net","abcd","password") or die("Could not connect to MySQL server!"); 
     @mysql_select_db("abcd") or die("Could not select database!"); 
     echo "You're connected to a MySQL database!"; 
     mysql_close(); 
  ? >
    class='wp-pagenavi' role='navigation'>
  • Toplam 100 sayfa, 1. sayfa.
  • 1
  • 2
  • 3
  • 4
  • 5
  • ...
  • 10
  • 20
  • 30
  • ...
  • Son »