Forum Moderators: coopster

Message Too Old, No Replies

Statcounter on .PHP Geo-Redirect Page

Statcounter on .PHP Geo-Redirect Page

         

iGLOBAL NiCK

7:49 am on Oct 10, 2009 (gmt 0)

10+ Year Member



Hello everyone, I have a index.php on one of my sites that automatically redirects a visitor to a different landing page depending on their location. Either a) they are in the USA or b) they are outside of the USA.

I am trying to find a free statcounter that will work with my index.php page. I do have a statcounter account at statcounter.com and I did read about adding echo ' in front of all the html code and ending with '; but for some reason when I try to do this, it doesn't work for me I get some sort of syntax error, I think I must be putting to many ';'s in the code. I do not know much about PHP, any help would be appreciated.

Here is my statcounter code if someone wants to modify it for me so I can use it with my index.php, I would greatly appreciate your help.

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=5193783;
var sc_invisible=1;
var sc_partition=34;
var sc_click_stat=1;
var sc_security="7d7c60c9";
</script>

<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="counters for myspace"
href="http://www.statcounter.com/myspace/"
target="_blank"><img class="statcounter"
src="http://c.statcounter.com/5193783/0/7d7c60c9/1/"
alt="counters for myspace" ></a></div></noscript>
<!-- End of StatCounter Code -->

iGLOBAL NiCK

7:55 am on Oct 10, 2009 (gmt 0)

10+ Year Member



Oh and here is my index.php page incase anyone wanted to see it, and maybe tell me where I can place the statcounter code in it:

<?php

$server = '#*$!x; // MySQL hostname
$username = '#*$!x'; // MySQL username
$password = '#*$!x'; // MySQL password
$dbname = '#*$!x'; // MySQL db name

$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
country
FROM
ip2nation
WHERE
ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
ORDER BY
ip DESC
LIMIT 0,1';

list($country) = mysql_fetch_row(mysql_query($sql));

switch ($country) {
case 'se':
// Get the Swedish to a Swedish
header('Location: [mysite.com');...]
exit;
case 'us':
// And redirect US visitors to
header('Location: [mysite.com);...]
exit;
default:
// The rest of the world can go to
header('Location: [mysite.com);...]
exit;
}

?>

coopster

11:47 pm on Oct 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi iGLOBAL NiCK and welcome to WebmasterWorld [webmasterworld.com]. Did you ever resolve this issue?

iGLOBAL NiCK

5:28 am on Oct 30, 2009 (gmt 0)

10+ Year Member



No, I am not sure how to incorporate a statcounter onto my index.php I have given the code for the statcounter in the above post, along with the index.php (which redirects depending on their location). Thanks for any help.

iGLOBAL NiCK

5:30 am on Oct 30, 2009 (gmt 0)

10+ Year Member



Basically the index.php redirects traffic, once the page is loaded if the user is in the USA then it sends them to the USA landing page and if they are outside the USA then they go to the other landing page, I could setup statcounter on the landing pages but I do not want to do that, I'd rather keep stats on the index.php

coopster

8:59 pm on Nov 1, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You're only going to track statistics on the index page? Not any other page?

One option may be to include your stat tracking automatically using the PHP auto_prepend configuration directive. Or if you are using any type of navigational server-side include for a header, menu, footer, etc. you could embed the code there too.

iGLOBAL NiCK

11:12 pm on Nov 1, 2009 (gmt 0)

10+ Year Member



Yes, only the index page, and all the index page is, is a re-direct to another page depending on their location. There is no header, menu, footer or anything its just a redirect script using PHP. Thanks for any help.