Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Util  /  Cookie   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tls.gif     Util  trs.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Cookie.php


Vis: Sample code, tutorial

Cookie, Sample code, tutorial

Sådan benyttes komponenten Cookie klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Cookie.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Cookie
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new Cookie($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

Cookie, Sådan vises komponenten

Sådan vises komponenten Cookie klassen

Der er ikke fundet noget

Vis: PHP source code

Cookie, PHP source code

Den fulde PHP kildekode for Cookie klassen

<?php
/**
 * @package util
 * @filesource
 * @see HTML_UTIL_COMPONENT_PATH.'/Cookie.php'
 * @copyright (c) http://Finn-Rasmussen.com
 * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
 * @author http://Finn-Rasmussen.com
 * @version 1.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Server.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
 * Set/get or delete a cookie
 * <code>
 * Usage:
 *   $cookie = new Cookie($name, $value, $time, $path, $domain, $secure);
 *   $rc    = $cookie->setCookie();
 *   $value = $cookie->getCookie();
 *   $rc    = $cookie->deleteCookie();
 * Or
 *   $rc    = Cookie::set($name, $value, $time, $path, $domain, $secure);
 *   $value = Cookie::get($name);
 *   $rc    = Cookie::delete($name);
 * </code>
 * @package util
 */

class Cookie {
    
/**
     * @var String $name The name of the cookie to get/set
     */
    
private $name ''
   
    
/**
     * @var String $value The value of the cookie
     */
    
private $value '';
   
    
/**
     * @var String $time The time in sec. 
     */
    
private $time ''
   
    
/**
     * @var String $path The root path of columns 
     */
    
private $path '';
   
    
/**
     * @var String $domain The domain 
     */
    
private $domain '';
   
    
/**
     * @var String $secure The secure 
     */
    
private $secure '';

    
/**
     * Constructor
     * @param String $name   The name of the cookie
     * @param String $value  The value, if any
     * @param String $time   The time 
     * @param String $path   The path
     * @param String $domain The domain
     * @param String $secure The secure
     */
    
function __construct($name=''$value=''$time=''$path=''$domain=''$secure='') {
        
$this->name   $name   != '' $name   COOKIE_NAME;
        
$this->value  $value  != '' $value  '';
        
$this->time   $time   != '' $time   COOKIE_TIME;
        
$this->path   $path   != '' $path   COOKIE_PATH;
        
$this->domain $domain != '' $domain COOKIE_DOMAIN;
        
$this->secure $secure != '' $secure 0;
    }

    
/**
     * Set the cookie information         
     * <code>
     * Usage:
     *    $cookie = new Cookie($name, $value, $time, $path, $domain, $secure);
     *    $rc = $cookie->setCookie($filename, $lineno);
     * </code>
     * @param  String $filename The File name
     * @param  String $lineno   The Line number
     * @return int The status
     */
    
function setCookie($filename=''$lineno='') {
        
$rc false;
        if (
headers_sent($filename$lineno)) {
            
$msg "Cookie->setCookie() detected headers_sent, see $filename, $lineno<br />\r\n";
            
Message::add($msg__FILE____LINE__);
        } else {
            
$rc setcookie($this->name$this->value$this->time$this->path$this->domain$this->secure);  // Set cookie info
        
}
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
            
$msg "Cookie->setCookie() $this->name, $this->value, $this->time, $this->path, $this->domain, $this->secure";
            
Log::debug($msg__FILE____LINE__);
        }
        return 
$rc;
    }

    
/**
     * Delete the cookie information
     * <code>
     * Usage:
     *    $cookie = new Cookie($name);
     *    $rc = $cookie->deleteCookie($filename, $lineno);
     * </code>
     * @param  String $filename The File name
     * @param  String $lineno   The Line number
     * @return int The status
     */
    
function deleteCookie($filename=''$lineno='') {
        
$rc false;
        if (
headers_sent($filename$lineno)) {
            
$msg "Cookie->deleteCookie() detected headers_sent, see $filename, $lineno<br />\r\n";
            
Message::add($msg__FILE____LINE__);
        } else {
            
$rc setcookie($this->name,'',(time()-2592000),'/','',0); // Delete the cookie
        
}
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
            
$msg "Cookie->deleteCookie() $this->name";
            
Log::debug($msg__FILE____LINE__);
        }
        return 
$rc;
    }

    
/**
     * Get the cookie value from the specified cookie name
     * <code>
     *    $cookie = new Cookie($name);
     *    $value  = $cookie->getCookie();
     * </code>
     * @param  String $name The name of the cookie value to get
     * @return String The cookie value or "" if not found
     */
    
function getCookie() {
        
$value ''// Nothing found
        
if (!empty($_COOKIE[$this->name])) {
            
$value $_COOKIE[$this->name];
        }
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
            
$msg "Cookie->getCookie() $this->name $value";
            
Log::debug($msg__FILE____LINE__);
        }
        return 
$value;
    }

    
/**
     * Delete the cookie with the specified cookie name
     * <code>
     *    $rc = Cookie::delete($name, $filename, $lineno);
     * </code>
     * @static         
     * @param  String $name     The name of the cookie value to delete
     * @param  String $filename The File name
     * @param  String $lineno   The Line number
     * @return int The status
     */
    
public static function delete($name$filename=''$lineno='') {
        
$cookie = new Cookie($name);
        return 
$cookie->deleteCookie($filename$lineno);
    }

    
/**
     * Set the cookie information
     * <code>
     * Usage:
     *    $rc = Cookie::set($name, $value, $time, $path, $domain, $secure, $filename, $lineno);
     * </code>
     * @static         
     * @param  String $name   The name of the cookie
     * @param  String $value  The value, if any
     * @param  String $time   The time 
     * @param  String $path   The path
     * @param  String $domain The domain
     * @param  String $secure The secure
     * @param  String $filename The File name
     * @param  String $lineno   The Line number
     * @return int The status
     */
    
public static function set($name=''$value=''$time=''$path=''$domain=''$secure=''$filename=''$lineno='') {
        
$cookie = new Cookie($name$value$time$path$domain$secure);
        return 
$cookie->setCookie($filename$lineno);
    }

    
/**
     * Get the cookie value from the specified cookie name
     * <code>
     *    $value = Cookie::get($name);
     * </code>
     * @param  String $name The name of the cookie value to get
     * @return String The cookie value or "" if not found
     */
    
public static function get($name) {
        
$cookie = new Cookie($name);
        return 
$cookie->getCookie();
    }
}
?>

Vis: HTML source code

Cookie, HTML source code

Den fulde HTML kildekode for Cookie klassen

<?
Der er ikke fundet noget
?>

Vis: Class methods

Cookie, Class methods

Her er 'klasse metoderne' for Cookie klassen:

  • __construct
  • setCookie
  • deleteCookie
  • getCookie
  • delete
  • set
  • get

Vis: Object vars

Cookie, Object vars

Her er 'objekt variable' for Cookie klassen:


MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.2.6-1+lenny8) 1.11
blank.gif