2Hi.Biz
Trang chủ | TWIG | Xtscript | Templates | Xtgem
xtscript Việt hóa 2015
AiChat.Wap.Sh
cookies
Cookies có thể được thiết lập đọc và xoá bằng xtscript
[...] = optional ... = your value
call cookie::set $name=...;$val=... ;$expire=...[;$force_current=1]
[assign $var = ]call cookie::get $name=...;$default=...
call cookie::delete $name=...[;$force_current=1]
Code ví dụ:
<!--parser:xtscript-->
# Cookie set in included file

# Cookie powered visits counter
# cookie settings
var $name = new_test_counter
var $path = /xtscript
var $expire = (60*60*24*365)

# delete cookie
get del
if $del
call cookie::delete $name=$name;$path=$path;$force_current=1
endif

# Get the current value of the cookie or set $val to 0 if no cookie is set
var $val = call cookie::get $name=$name;$default=0
# increment the value
var $val = ($val+1)
# Set the cookie to the new value
call cookie::set $name=$name; $val=$val; $expire=$expire;$path=$path

# Set type for 1st 2nd 3rd 4th
var $len = call strlen $val=$val
var $last_digit = call substr $val=$val;$start=($len-1)
if $last_digit == 1
var $type=st
elseif $last_digit == 2
var $type=nd
elseif $last_digit == 3
var $type=rd
else
var $type=th
endif
# 11th 12th 13th exceptions
var $last_two_digits = call substr $val=$val;$start=($len-2)
if $last_two_digits == 11 or $last_two_digits == 12 or $last_two_digits == 13
var $type = th
endif
if $val == 1
var $message= Welcome new visitor
elseif $val >= 20
var $message= You are a regular visitor
elseif $val >= 10
var $message= You come here a lot
else
var $message= Welcome back
endif

# Show counter
print <b>$message this is your $val$type visit</b><br />
<!--/parser:xtscript-->
Code đã chạy;
Welcome new visitor this is your 1st visit