SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Create Cookie - with array (need help)

    Hi Guys,

    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.

    PHP Code:
    function country_to_continent$country ){
        
    $continent '';
        if( 
    $country == 'AF' $continent 'AS';
        --
    CUT OFF DUE TO TEXT LIMITFIND THE FULL CODE HEREhttp://infinitymedia.pastebin.com/7WWDeyVT
        
    return $continent;


    My current code is below


    HTML Code:
    <!-- 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

  2. #2
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

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

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand, how do i implement that.

  6. #6
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make the choice of to whether or not to include the file and to run the code in php.

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

  7. #7
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That wont do anything that will just attach the js to a html page.

  8. #8
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im losing myself here, when i wake up tomorrow well carry on. Im really tired right now it's late in the UK

  10. #10
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Been there.

    *Pats on back*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •