SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Colorado, USA
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script for "saving" a country-specific URL

    If you go to the following thread: http://www.sitepoint.com/forums/showthread.php?t=206733 you will notice I was given some code in order to allow visitors to "save" their selection of their country-specific site so that they will be taken directly do it from that point forward. However, when I try to use it, I get an error on the fourth line of the first snippet. I believe I need to fill in those quotation marks, but I have no idea what to fill them in with, and my attempts to contact the first person to give me the code have failed. ANY help, even if you need to give me a completely different solution, would be much appreciated!
    Terri Eades - Web/Graphic Designer - www.terrieades.com

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just download the countries to ip database for free. Google it and make matches against it.

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // default country
    $country 'us'

    // do we have country in GetPostCookie?
    if(isset($_REQUEST['country']))
       
    $country $_REQUEST['country'];

    // save current setting in cookie

    $one_month 3600 24 30;
    setcookie("country"$countrytime()+ $one_month"/"); 
    hth

  4. #4
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Colorado, USA
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks VERY much for the code!! I am having one small problem with it, though. If you go here (http://www.classicallydivine.com/tests), you will see the error message that pops up. (It might also be helpful to look at the source code, so you can see how I have things set up.) It seems there is a problem with this line:

    PHP Code:
    setcookie("country"$countrytime()+ $one_month"/"); 
    Any further help would be greatly appreciated!
    Terri Eades - Web/Graphic Designer - www.terrieades.com

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    United States
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The setcookie() call should come before any output to the browser. Have you tried that yet?

  6. #6
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Colorado, USA
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worked! I put all of my PHP code at the very top of my source file, (before the head tags and everything), and now I don't get an error. However, when I "view source" in Internet Explorer, I don't see the code. Is this normal, since it is processed before anything is output to the browser?

    THANKS!
    Terri Eades - Web/Graphic Designer - www.terrieades.com

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    United States
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct, the PHP code is processed by the server (hence Hypertext Preprocessor) and only the actual output (html tags, text, etc) will show up when someone looks at the page. You don't actually have to put ALL of your PHP code before any output, just special ones like "header()", "setcookie()", and probably a few others.


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
  •