Create Cookie - with array (need help)

[FONT=“Georgia”]Hi Guys,
[SIZE=“3”]
If you’ve seen from my previous posts in this forum, you may have noticed that i’m a newbie when it comes to javascript, anyway.

I’m trying to create an array sort of thing to convert the country name’s to continent, and set it as a cookie. I spent all that time writing a PHP script for this same thing only to find out that my webhost does not have the maxmind apache module.

I also don’t know how to get the value of the country from a javascript function.
[/SIZE]

function country_to_continent( $country ){
    $continent = '';
    if( $country == 'AF' ) $continent = 'AS';
    --CUT OFF DUE TO TEXT LIMIT, FIND THE FULL CODE HERE: http://infinitymedia.pastebin.com/7WWDeyVT
    return $continent;
}


My current code is below

<!-- Start Maxmind's Work | And Yes I know maxmind isn't a persons name -->
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<br>Country Code:
<script language="JavaScript">document.write(geoip_country_code());</script>
<!-- End Maxmind's Work | And Yes I know maxmind isn't a persons name -->

<!-- Start Maxmind's Work | And Yes I know maxmind isn't a persons name -->
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">document.write("<br>Country Code:".geoip_country_code());</script>
<!-- End Maxmind's Work | And Yes I know maxmind isn't a persons name -->


<script type="text/javascript">
function getCookie(c_name){if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + "=");if (c_start!=-1){c_start=c_start + c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if (c_end==-1) c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}return "";}
function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());}

function popupLocate(){
	cookie=getCookie("cache-location");
	if(cookie!=null && cookie!=""){
		//Nothing To Put Here
	} 
	
	else {
		setCookie("cache-location"," <!-- I don't know how to put the continent code here --> ",365);
	}
}
</script>

<a href="#" onClick="popupLocate()">Do "popupLocate()"!</a>


Thanks in Advance

Humza[/FONT]

Instead of putting a function inside of a cookie. It’s easier to put in a keyword into the cookie that tells the script to run function.


if(cookieVal=="runContinentFunction")
{
//run it
}

I can’t change that, maxmind did it like that it’s easier for them, look at http://j.maxmind.com/app/geoip.js then you’ll understand, its a javascript file but powered by something else.

That wont do anything that will just attach the js to a html page.

Change what? I don’t think you have to change anything.

I’m saying to put in a keyword in the cookie and run whichever function you want based on conditionals…

I don’t understand, how do i implement that.

Make the choice of to whether or not to include the file and to run the code in php.


<?

//if cookie set
{
echo "<script src='maxmindorwhatever.js'></script>"
}


?>

You’re losing me here.

I’m saying to run the file and execute the code when your cookie is set. And not run it when it’s not. You do it based on keyword opposed to putting an entire function in your cookie.

Im losing myself here, when i wake up tomorrow well carry on. Im really tired right now it’s late in the UK

Been there.

Pats on back