logo
Home XtGem- Templates- XtScript- bottom
Translate this page
Cookies can be set read and deleted using 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]
cookies Must be set in the current Xtscript they cannot be set in an a local or external included file
or from a direct local or external user defined function
If you try the cookie may be set but you will probably get a white screen
You cannot set the domain for the cookie
Show in textarea
<!--parser:xtscript-->
# Cookie set in included file 

# Cookie powered visits counter
# cookie settings
var $name = new_test_counter
var $path = /manual/basics/default
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-->
Show in textarea
Reload
Welcome back this is your 9th visit
Delete cookie
Powered by XtGem
About us Contact Forum top