Forum Moderators: coopster

Message Too Old, No Replies

Geo-Targeting in Joomla using PHP Module

         

Lensa

2:35 pm on Sep 22, 2008 (gmt 0)

10+ Year Member



I'm pretty new to PHP (changing over from asp) and I've been pulling my hair out trying to get a geo-targeting script to run in a php module within Joomla. The script works no problem when it is built directly into the HTML template - but if I put the second half of the code into a php module in Joomla it no longer works? I have included my script below - any ideas what I am doing wrong?

Many thanks!

-----------
Code included at the head of every page in the template:
-----------
<?php
{ if(isset($_COOKIE["geoCode"]))
{ $countryCode = $_COOKIE["geoCode"]; }
else
{ $countryCode = file_get_contents('http://example.com/country.php?ip='.$_SERVER['REMOTE_ADDR']);
setcookie("geoCode", $countryCode, time()+15552000, "/", ".mysite.com", 0); } } ?>

------------
Code that will work if also included in the template, but will not work in PHP Module's
------------
<?php
if( $countryCode == "UK")
{
echo "Hi there UK";
}
else
{
echo "Hello world";
}
?>

[edited by: dreamcatcher at 3:08 pm (utc) on Sep. 22, 2008]
[edit reason] use example.com. Thanks. [/edit]

Philosopher

3:03 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



by "not working" what do you mean?

Is the code throwing an error?

Is the php in the module simply not being executed?

There are some joomla addons that allow php to be executed. Are you using one of these?

A bit more info could be useful.

Lensa

3:15 pm on Sep 22, 2008 (gmt 0)

10+ Year Member



Hi, Sorry for that, I'll clarify a bit.

I'm using a Joomla addon that allows you to include PHP in a module. I am in the UK - if I run the second part of the script as part of the template I get the return message "Hi there UK" showing the geo targeting script is working correctly - but if I include it as part of the PHP module I get the "hello world" reply (its not recognising me as from the UK). I can put it on the page twice, once in the module and once on the template, and get two different replies even though it should be calling on the same information from the cookie?

It seems to be something to do with the way the php is run in the module that stops it from working correctly? Perhaps I need to alter my script to compensate?