vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Display banner depending on browser setting? (https://vborg.vbsupport.ru/showthread.php?t=121346)

Yorixz 07-16-2006 06:36 PM

Display banner depending on browser setting?
 
Because of the requirements of one of my ad providers (50% of the impressions have to be to people from Canada, the USA or UK) I'm trying to figure out the best way to display these ads to the right visitors (and display alternative ads to the others).

I've noticed vBulletin allows (a few) PHP functions to be used in templates, sadly there is no function available to check for the browser language.

I've found the following code on php.net (and changed it a bit)
PHP Code:

function chooseLang($availableLangs){
   
$pref=array();
   foreach(
split(','$_SERVER["HTTP_ACCEPT_LANGUAGE"]) as $lang) {
       if (
preg_match('/^([a-z]+).*?(?:;q=([0-9.]+))?/i'$lang.';q=1.0'$split)) {
           
$pref[sprintf("%f%d"$split[2], rand(0,9999))]=strtolower($split[1]);       
       }
   }
   
krsort($pref);
   return 
array_shift(array_merge(array_intersect($pref$availableLangs), $availableLangs));
}
 
if(
chooseLang(array('en''sv''en''nl')) == 'en'){
echo 
1;
} else {
echo 
2;


And I'm a bit wondering how to use this, I haven't got too much experience with plugins, I wouldn't know how to return a value to one of the templates so a little help or a pointing in the right direction would be very appreciated.

Yours,

Yorixz

Alright, I got a PM with some info about it on vB.com, but anyway, I managed to get the code working, it selected the right language, until I changed it some and now all it does is complaining that my field isn't found.
i'm using this code:
PHP Code:

function favoriteLang($availableLangs){
   
$pref=array();
   foreach(
split(','$_SERVER["HTTP_ACCEPT_LANGUAGE"]) as $lang) {
       if (
preg_match('/^([a-z]+).*?(?:;q=([0-9.]+))?/i'$lang.';q=1.0'$split)) {
           
$pref[sprintf("%f%d"$split[2], rand(0,9999))]=strtolower($split[1]);       
       }
   }
   
krsort($pref);
   return 
array_shiftarray_mergearray_intersect$pref$availableLangs), $availableLangs) );
}

if ( !isset( 
$vbulletin->session->vars['adlang'] ) ) {
    
$lang favoriteLang( array( 'en''sv''nl''fr''pt''es''pl''no''de' ) );
    
//$_SESSION['adlang'] = $lang;
    
$vbulletin->session->db_fields['adlang'] = type_char;
    
$vbulletin->session->set('adlang'$lang);  
    
$adcode2 'session now set';
} else {
    
$lang $vbulletin->session->vars['adlang'];
    
$adcode2 'session already set!';
}

switch(
$lang)
{
    case 
'en':
    case 
'fr':
        
$adcode 'adcode clicksor, ';
        break;
    default:
        
$adcode 'adremedy, ';
        break;




All times are GMT. The time now is 10:03 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.01002 seconds
  • Memory Usage 1,732KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)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