vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Best practices for storing and using data in the vB cookie (https://vborg.vbsupport.ru/showthread.php?t=203836)

davide101 02-01-2009 02:52 PM

Best practices for storing and using data in the vB cookie
 
I would like someone to point me to a simple tutorial on the right way to write and read data from a cookie (the vB one in this case) using php.

Here's my goal: the first time a member visits my site, I want to show an expanded 'reasons to join' guest box. On subsequent pageviews, I would like to show a much smaller version. I think the easiest way to do this is set a cookie when someone visits and only show the big box if the cookie isn't set.

Can someone walk me through the 50,000ft view of how I should best go about this? I've never done anything with cookies and want to do this the right way in terms of coding standards and end-user speed.

Dismounted 02-03-2009 04:43 AM

Your friend is vbsetcookie(). When fetching the cookie, clean the cookie first using the vB Input Cleaner Class (and make sure you have added on the cookie prefix when fetching, this is not required when setting).

davide101 02-03-2009 02:53 PM

Dismounted, thank you! I searched for more info and came across a very useful example that's also by you: https://vborg.vbsupport.ru/showpost....39&postcount=4

--------------- Added [DATE]1233680678[/DATE] at [TIME]1233680678[/TIME] ---------------

For those of you that want a simple way to show something different to first time visitors, here's the plugin I'm using at Global Start:

Code:

if (!isset($_COOKIE[COOKIE_PREFIX . 'FirstVisit']))
{
  // set variable for use in templates
  $firstVisit = true;

  // set cookie
  vbsetcookie('FirstVisit', '0', permanent);
}

Now if $firstvisit is true, I can call different code in my templates.

Dismounted 02-04-2009 05:14 AM

You do not need the third argument (it defaults to true). If you need to use it, you need to use "true" or "false", not "permanent".


All times are GMT. The time now is 05:56 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01061 seconds
  • Memory Usage 1,714KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete