Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
first time site visit cookie
Hey
how can I create a cookie on first time site visit?
I want to call a JS function name “startplayer”,
but only on the first time you visit the website.
and I will put that cookie in every page head tag.
(or if you know JS and can please help me here)
Last edited by THE BLUE DRAGON (2009-11-29 18:27:58)
Offline
#2 2009-11-24 15:15:01
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: first time site visit cookie
re #1: chs_cookie looks promising.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: first time site visit cookie
Please post back your solution to #1 I’m gonna do this for a client.
Offline
Re: first time site visit cookie
uli wrote:
re #1: chs_cookie looks promising.
I tried, I really did, but I just don’t understand how to work with this plugin.
can you please guide me?
all I need is one time use cookie
if the cookie not exist in the visitor computer do that (call a function),
and if it does, so do nothing.
so I will take this cookie and add it to the head tag of every page,
and create the cookie on the body tag with ‘onunload’.
Last edited by THE BLUE DRAGON (2009-11-24 19:34:36)
Offline
#5 2009-11-24 20:59:10
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: first time site visit cookie
Gil, it was a recommendation, I never worked with it. Like I said: It looks promising.
But in the meantime I had an opportunity to play a little with its tags.
In the head portion EDIT 2: As the very first entry of my page I put:
<txp:chs_set_cookie cookie="THE_BLUE_DRAGON" value="TheBlueDragon-Cookie_is_set" />
In the body I put:
<txp:chs_cookie_default cookie="THE_BLUE_DRAGON">
TheBlueDragon-Cookie does not exist.
</txp:chs_cookie_default>
<txp:chs_cookie_exists cookie="THE_BLUE_DRAGON">
TheBlueDragon-Cookie is set.
</txp:chs_cookie_exists>
… which is kinda like an if/else test, the else tag doesn’t work here. The thing throws errors at you like pebbles, but the “Live status shelter” is pebble-tight, and chs_cookie seems to work. Umm, if there weren’t this cacheing issue, I presume. At least if I call different pages or cmd-shift-refresh the page (Mac) it works relyably.
EDIT: Corrected a fault in the code, the correct code didn’t reduce errors, though.
Last edited by uli (2009-11-24 21:59:25)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: first time site visit cookie
That is very nice!
Thank you Uli !
working good,
except that when you close the browser and go into the site again the cookie is getting lost and it call my function again every time you visit the site.
if you on the site and just moving between pages then it works fine and call my function just once on the first visit.
but when you close the browser and open it again and go to the site then it will start from the begining and call my function once again.
Offline
Re: first time site visit cookie
chs_cookie is using setcookie and is not including a value for the expire parameter. This means that the “cookie will expire at the end of the session (when the browser closes).”
You can change this line
setcookie($thevar, $atts['value']);
to
setcookie($thevar, $atts['value'],time()+3600*24*365);
to set the cookie to expire in 1 year
Last edited by MattD (2009-11-25 00:11:35)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#8 2009-11-25 00:14:23
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: first time site visit cookie
Gil, you can use <txp:php>setcookie('THE_BLUE_DRAGON', 'TheBlueDragon-Cookie_is_set', time()+3600*24);</txp:php>
instead of the txp:chs_set_cookie
line.
Edit: As usual, Matt was faster :)
Last edited by uli (2009-11-25 00:15:58)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: first time site visit cookie
Thanks to both of you!
now the cookie got a lot of better flavor that stays much longer ;)
Offline
Pages: 1