Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 38

Thread: language cookie

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

    Default

    Quote Originally Posted by tech_support View Post
    PHP Code:
    $ip $_SERVER['HTTP_HOST']; 
    The above would get the host name not the ip address. If you wanted just the ip, you would have to use $_SERVER["REMOTE_ADDR"];
    "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. #12
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    So, to get back to the first question; to remember a language choice, I just place the following into the choosen language ? Correct ?

    Code:
    $cookiename = "tracker";
    $olddata = $_COOKIE[$cookiename];
    $newdata = "Visited page " . $_SERVER['PHP_SELF'];
    $data = $olddata . $newdata;
    setcookie($cookiename,$data,time()+3600);

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

    Default

    And does the above redirect at next visit ?

  4. #14
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    chechu, so sorry to interrupt again.

    Thanks to tech_support and thetestingsite for your input.
    May I know after creating the cookies, how to I test and view the result?

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

    Default

    Quote Originally Posted by chechu View Post
    So, to get back to the first question; to remember a language choice, I just place the following into the choosen language ? Correct ?

    Code:
    $cookiename = "tracker";
    $olddata = $_COOKIE[$cookiename];
    $newdata = "Visited page " . $_SERVER['PHP_SELF'];
    $data = $olddata . $newdata;
    setcookie($cookiename,$data,time()+3600);
    The above would save a cookie for the pages that the user has visited. To make the language one, simply change a few items.

    Code:
    $cookiename = "lang";
    $data = $languageChoice; //the variable for the language that was choosen.
    setcookie($cookiename, $data, time()+3600);
    As for joycie, you could use the following to check the data.

    Code:
    $theCookie = $_COOKIE['tracker']; //change "tracker" to your saved cookiename.
    
    echo $theCookie; //echos the data stored in the cookie.
    Hope this helps both of you.
    "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

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

    Default

    Sorry, but I'm really no good at php.
    What goes on the selection page, and what goes on the selected page ? In the <head> ? Do I need to put <!? php somewhere as well ?
    Questions from a dummie ...

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

    Default

    Lets make a simple file (call it langTest.php), in this file we will place the following code:

    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
       }
    
    }
    ?>
    That should do it, let me know if you need any more help.
    "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

  8. #18
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    Would appreciate if someone could help:
    Tested using the above tracking php codes but returned with error--
    Parse error: syntax error, unexpected T_STRING on line 7

    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);  
    ?>
    
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>hello
    </body>
    </html>

  9. #19
    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

    unless I am mistaken, and I might be, I never really knew much about php and I am forgetting more everyday...

    $ip = $_SERVER["REMOTE_ADDR"]
    is missing it's semicolon *;* at the end, and the parse error is coming from trying to combine the last two lines into one, as there is no separator.
    {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

  10. #20
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    Thanks to BLiZZaRD.

    I use the codes below and when I go to the page http://domain.com/tracker.php, the page shows this message "Visited page /tracker.php"

    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);  
    ?>
    <?php
    $theCookie = $_COOKIE['tracker']; 
    echo $theCookie; //echos the data stored in the cookie.
    <html>
    <head>
    <title>Test</title>
    </head>
    <body></body>
    </html>
    Is this the correct way to call? Why is my IP and date visited not shown on the page? Pardon me for my query. I am a newbie in PHP. Thanks for any help.

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
  •