View Full Version : Plugin Help
woostar
06-08-2007, 05:30 PM
Hi there,
I've subscribed to a GeoIP list so I can server different contents to members in different countries.
What is the correct syntax for the code below (or is it correct):-
if (isset($_COOKIE['GeoIP'])) {
include "geoip.php";
set_cookie("GeoIP", $countrycode, 3600);
}
and how do I get this to run as a plugin on every page.
Thanks in advance
W.>
Dismounted
06-09-2007, 03:43 AM
Cleaned up your code :)
if (isset($_COOKIE['GeoIP']))
{
include_once('geoip.php');
set_cookie('GeoIP', $countrycode, 3600);
}
You would hook it at global_start.
woostar
06-09-2007, 01:53 PM
Thanks Dismounted,
Hooked it at global_start and used vbsetcookie (coz set_cookie doesn't work).
Below is the code I used just incase it helps anyone else.
if (!isset($_COOKIE['GeoIP'])) {
// put geo locating code here
include("geoip.php");
$countryCode = getCountryCode($_SERVER['REMOTE_ADDR']);
// set cookie
vbsetcookie("GeoIP",$countryCode,permanent);
} else {
$countryCode = $_COOKIE['GeoIP'];
}
Dismounted
06-10-2007, 02:59 AM
Note that vbsetcookie() will add your cookie prefix to the cookie, so it actually should be:
if (!isset($_COOKIE[COOKIE_PREFIX . 'GeoIP']))
{
// put geo locating code here
include('./geoip.php');
$countryCode = getCountryCode($_SERVER['REMOTE_ADDR']);
// set cookie
vbsetcookie('GeoIP', $countryCode, permanent);
}
else
{
$countryCode = $_COOKIE[COOKIE_PREFIX . 'GeoIP'];
}
woostar
06-10-2007, 12:12 PM
Ah, Nice one.
Thanks for your help Dismounted.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.