Jump to content

Will this piece of code work


craigbruiners

Recommended Posts

<?

if ($COOKIE['visitor_language']== "en") {

$lg_id = "UA-1436977-1";

} elseif ($COOKIE['visitor_language']== "fr") {

$lg_id = "UA-1436987-1";

} elseif ($COOKIE['visitor_language']== "de") {

$lg_id = "UA-1436993-1";

} elseif ($COOKIE['visitor_language']== "nl") {

$lg_id = "UA-1436998-1";

} else {

$lg_id = "UA-1437004-1";

}

?>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">

</script>

<script type="text/javascript">

_uacct = "<?=$lg_id?>";

urchinTracker();

</script>

 

It goes through this code once the user comes into the site from the different countries.

Link to comment
Share on other sites

if you ask "if this works" we will assume it doesn't work

yet you have not cared to explain why it doesn't work?

maybe an error...something???

 

from just reading it looks like it works, of course this depends on cookies already being set, I don't see the code where you set the language cookie for the user

Link to comment
Share on other sites

Well i just wanted you to check if there was any syntax error in the code, seeing that it doesn't wanna work, and seeing that you said that the code is fine, thanks alot for that hey, and thanks alot for ur reply, really appreciated.

 

This is where we set the language in the cookie. This is the code for the cookies:

 

<?

    /* Script to run at starup */

       

    /* Detecting browser's default language */

    if (!isset($_COOKIE['visitor_language']))  {

        $BrowserLang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);

        switch($BrowserLang) {

            case "en":

                $_SESSION['DEFAULT_LANG'] = "en";

                break;

            case "fr":

                $_SESSION['DEFAULT_LANG'] = "fr";

                break;

            case "de":

                $_SESSION['DEFAULT_LANG'] = "de";

                break;

            case "nl":

                $_SESSION['DEFAULT_LANG'] = "nl";

                break;

            case "es":

                $_SESSION['DEFAULT_LANG'] = "es";

                break;

        }     

    }

    /* Set Default site language region */

   

    if (!isset($_COOKIE['visitor_language']))  {

        if (getenv('HTTP_X_FORWARDED_FOR')) {

            $visitor_ip = getenv('HTTP_X_FORWARDED_FOR');

        } else {

            $visitor_ip = getenv('REMOTE_ADDR');

        }

       

        $VisitorInfo = file('http://api.hostip.info/get_html.php?ip='. $visitor_ip .'&position=true');

   

        if($VisitorInfo != "") {

                $VisitorRegion = substr($VisitorInfo[0], -4, 2);

                switch($VisitorRegion) {

           

                    case "FR":

                        $_SESSION['DEFAULT_LANG'] = "fr";

                        break;

                    case "DE":

                        $_SESSION['DEFAULT_LANG'] = "de";

                        break;

                    case "NL":

                        $_SESSION['DEFAULT_LANG'] = "nl";

                        break;

                    case "ES":

                        $_SESSION['DEFAULT_LANG'] = "es";

                        break;

                }

        }

    }

    /* Register default language in cookie */

    $time = time();

    if (isset($_COOKIE['visitor_language']))  {

      $_SESSION['DEFAULT_LANG'] = $_COOKIE['visitor_language'];

      setcookie ("visitor_language",$_SESSION['DEFAULT_LANG'], $time+(60 * 60 * 24 * 60));

    } else {

      $visitor_lang_pref = $_SESSION['DEFAULT_LANG'];

      setcookie ("visitor_language",$visitor_lang_pref, $time+(60 * 60 * 24 * 60));

    }

 

?>

 

 

Hope this will give u more detail, thanks again. :D;D

Link to comment
Share on other sites

Well im testing it the whole time and ran out of ideas of how to make this thing to work, coz my one friend in France is testing and when he goes to the website it brings back the english number $lg_id = "UA-1436977-1" instead of the french number $lg_id = "UA-1436987-1", so how do i go from here, coz i've came to this point where im stuck and feel so stupid(then i ask myself what am i doing in programming). ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.