Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 38

Thread: language cookie

  1. #21
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You would have to do something like the following in order to get it to display right:

    Code:
    <?php
    $cookiename = "tracker";
    $olddata = $_COOKIE[$cookiename];
    $newdata = "Visited page " . $_SERVER['PHP_SELF'];
    $data = $olddata . $newdata;
    $ip = $_SERVER["REMOTE_ADDR"];  
    setcookie($cookiename,$data,time()+3600);  
    
    $theCookie = $_COOKIE['tracker']; 
    ?>
    
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    
    <?php
    
    echo $theCookie; //echos the data stored in the cookie.
    echo 'IP Address: '.$ip; //echos IP Address found by REMOTE_ADDR above
    ?>
    
    </body>
    </html>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  2. #22
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Aye, looks good to me, and just to explain incase you couldn't tell by test's script there, in your original code you were calling the variable $theCookie;

    Yet in your script definitions "theCookie" was never defined. So basically you were giving your scripts names for all it's apples then asking it to show you an orange.

    Just notice how test's script defines what $theCookie actually is, so when it is called for in the echo' the script KNOWS what to display
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #23
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Thanks for explaining it for me Blizzard, I was looking at it last night and thought it could use some explaining, but never got around to it.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #24
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    No problem buddy, you do it for me as well. Team work and all that. Plus later when I have the same problems cause I am so forgetful, I can look at my own posts and answer myself...

    ROTF!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #25
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    Many thanks to both thetestingsite and BLiZZaRD for your time and patience.
    I could now view my own IP when I access the php file online.

    If I want to keep a record of what people do when they visit a webpage of my site, say downloading picture or songs, etc, may I know how I could modify the script so that only I (and not others) could view the IPs of people who visit my site and what he/she did on my site?

    Any help would be greatly appreciated.

  6. #26
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    That is a tricky question.

    Yes there are ways to make it so you can find and follow an IP around your site. I am not so sure you will be able to "see" what they are doing.

    About the best you could do is see which pages they go to and for how long.

    One of the best (and easier) ways to do this is to get a high profile stat counter.

    look into BBClone. Simple set up, updated often and has more stats than you can remember. I used it very well for a very long time until my site grew so large and popular that it was starting to fall behind.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #27
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I this code has something wrong in it. I am looking for something that gives the user a drop down box they pick the langage that they want. after clicking go it takes them to http://www.YOURDOMAIN.com/en or http://www.YOURDOMAIN.com/ch

    Code:
    <?php
    
    $homepage = 'http://'.$_SERVER["HTTP_HOST"].'/';
    
    if ($_REQUEST['act'] == "setLang") { 
    
    //check to see if the form has been submitted!
    
        if ($_REQUEST['lang'] == "") {
              header('Location: '.$_SERVER["PHP_SELF"]); 
    
    //if language selection is empty, redirect to form!
        }
    
        else {
    //if language was selected, save it in a cookie, then redirect to appropriate page!
            $lang = $_REQUEST['lang'];
            setcookie("language, $lang, time()+3600);
            header('Location: '.$homepage.$lang);
        }
    }
    
    else {
    
    //if form has not been submitted
    
       if (@$_COOKIE['language'] != "") {
    /* check to see if language cookie is empty. If not, redirect to appropriate page. */
    
       header('Location: '.$homepage.$_COOKIE["language"]);
       }
    
       else {
    
    //if cookie is empty, display form
    ?>
    
    <html>
    <head>
    <title>Language Cookie Test</title>
    </head>
    <body>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type="hidden" name="act" value="setLang">
    
    <select name="lang">
      <option value="en">English</option>
      <option value="sp">Spanish</option>
      <option value="ru">Russian</option>
    </select>
    
    <input type="submit" value="Set Language">
    </form>
    
    </body>
    </html>
    <?php
       }
    
    }
    ?>
    Also i need it to remember what the user choosed.
    The web in one word.

  8. #28
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You say there is something wrong with the code, but you don't say what it is/isn't doing. By looking at the code, it should work fine; however, if you say it has a problem, let us know what it is.

  9. #29
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Hey,
    Below you will find the cookie to remember the language choice.
    But this one is using a form. How is the code, if I let people choose by just clicking a test link ? (see here ?
    Code:
    <?php
    
    $homepage = 'http://'.$_SERVER["HTTP_HOST"].'/';
    
    if ($_REQUEST['act'] == "setLang") { 
    
    //check to see if the form has been submitted!
    
        if ($_REQUEST['lang'] == "") {
              header('Location: '.$_SERVER["PHP_SELF"]); 
    
    //if language selection is empty, redirect to form!
        }
    
        else {
    //if language was selected, save it in a cookie, then redirect to appropriate page!
            $lang = $_REQUEST['lang'];
            setcookie("language, $lang, time()+3600);
            header('Location: '.$homepage.$lang);
        }
    }
    
    else {
    
    //if form has not been submitted
    
       if (@$_COOKIE['language'] != "") {
    /* check to see if language cookie is empty. If not, redirect to appropriate page. */
    
       header('Location: '.$homepage.$_COOKIE["language"]);
       }
    
       else {
    
    //if cookie is empty, display form
    ?>
    
    <html>
    <head>
    <title>Language Cookie Test</title>
    </head>
    <body>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type="hidden" name="act" value="setLang">
    
    <select name="lang">
      <option value="en">English</option>
      <option value="sp">Spanish</option>
      <option value="ru">Russian</option>
    </select>
    
    <input type="submit" value="Set Language">
    </form>
    
    </body>
    </html>
    <?php
       }
    
    }
    ?>

  10. #30
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    To save the cookie as a link, try the following.

    Code:
    <?php
    
    $homepage = 'http://'.$_SERVER["HTTP_HOST"].'/';
    
    if ($_REQUEST['act'] == "setLang") { 
    
    //check to see if the form has been submitted!
    
        if ($_REQUEST['lang'] == "") {
              header('Location: '.$_SERVER["PHP_SELF"]); 
    
    //if language selection is empty, redirect to form!
        }
    
        else {
    //if language was selected, save it in a cookie, then redirect to appropriate page!
            $lang = $_REQUEST['lang'];
            setcookie("language, $lang, time()+3600);
            header('Location: '.$homepage.$lang);
        }
    }
    
    else {
    
    //if form has not been submitted
    
       if (@$_COOKIE['language'] != "") {
    /* check to see if language cookie is empty. If not, redirect to appropriate page. */
    
       header('Location: '.$homepage.$_COOKIE["language"]);
       }
    
       else {
    
    //if cookie is empty, display form
    ?>
    
    <html>
    <head>
    <title>Language Cookie Test</title>
    </head>
    <body>
    
    <a href="?act=setLang&lang=en">English</a>
    <a href="?act=setLang&lang=sp">Spanish</a>
    <a href="?act=setLang&lang=ru">Russian</a>
    
    
    </body>
    </html>
    <?php
       }
    
    }
    ?>
    Hope this helps.

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
  •