vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   GeoIP condition (https://vborg.vbsupport.ru/showthread.php?t=278368)

steveneff 02-10-2012 12:20 PM

GeoIP condition
 
I have GeoIP installed on my website (not in vbulletin) and want to use a condition based on country

I have put this code in forums/index.php

PHP Code:

$efvip $_SERVER['REMOTE_ADDR'];include('/home/myaccount/public_html/geo/geoip.inc');$gi geoip_open('/home/myaccount/public_html/geo/ip/GeoIP.dat',GEOIP_STANDARD);$mygig geoip_country_code_by_addr($gi$efvip);$mycountry = array('AL','AZ'); 

In my forumdisplay template I have tried the following condition but the template gives an error in functions.

PHP Code:

<vb:if condition="!in_array($mygig,$mycountry, true)"


Any ideas how I can get this to work?

kh99 02-10-2012 12:54 PM

Try adding this to your code in index.php:

Code:

vB_Template::preRegister('FORUMDISPLAY', array('mygig' => $mygig, 'mycountry' => $mycountry));

steveneff 02-10-2012 01:14 PM

Still no go, when I try to add the condition in the template I get

Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3416

kh99 02-10-2012 01:18 PM

Which version of vb are you running?

steveneff 02-10-2012 01:25 PM

4.1.2 Patch Level 3

I also got a server error with your code

kh99 02-10-2012 01:29 PM

Quote:

Originally Posted by steveneff (Post 2298218)
I also got a server error with your code

I tried it and there doesn't seem to be any errors in it, but it does need to be somewhere after global.php is included.

ETA: There is something else you could try instead of adding my code:

Code:

<vb:if condition="!in_array($GLOBALS['mygig'],$GLOBALS['mycountry'], true)">

steveneff 02-10-2012 01:44 PM

Moving your first code down the page removed the server error but still not liking my condition

With that removed and using your condition I get

Could not find phrase ' The following template conditional expression contains function calls:
GLOBALS('mygig')
GLOBALS('mygig')

kh99 02-10-2012 02:01 PM

Oops - that's because I was being stupid. It should be $GLOBALS[] - I fixed the above code.

steveneff 02-10-2012 02:06 PM

That clears the function calls but gives my original error

Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3416

kh99 02-10-2012 02:07 PM

Hmm...and that error goes away when you remove the condtion?


All times are GMT. The time now is 02:33 PM.

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.02548 seconds
  • Memory Usage 1,735KB
  • 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_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete