Results 1 to 5 of 5

Thread: Cookie not working in IE. Please check my coding.

  1. #1
    Join Date
    Apr 2006
    Posts
    198
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Question Cookie not working in IE. Please check my coding.

    Hello everyone,

    I'm having trouble with writing a cookie in IE.

    I'm using the code shown below and it's working fine in Firefox but not in IE.

    This code is the first thing on the page, placed before the document type and the opening HTML tag
    PHP Code:
    <?php

    if ($_REQUEST['send']=="yes")
            {
            
    setcookie("return_user"$value);
            
    setcookie("return_user"$valuetime()+60*60*24*360);  /* expire in 1 year */
            
    setcookie("return_user"$valuetime()+60*60*24*360"/"".example.com"0);
            }

    ?>
    In case it's not obvious, the idea is that when the user returns to the page after having successfully filled out a form they arrive at form.php?send=yes and a cookie gets written.

    Anyone know how I can get this working in IE and Firefox?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Why are you setting the same cookie three times?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2006
    Posts
    198
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Why are you setting the same cookie three times?
    Because I don't know what I'm doing

    I'll change that then.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    http://www.php.net/manual/en/function.setcookie.php


    setcookie('name','value','timeexpires','path','domain','secure')

    If secure is TRUE, then it's only available on HTTPS pages.... ignore that for now.
    The domain doesn't need to be set... unless you want it only to work with www.yourpage.com or something.yourpage.com, not just *.yourpage.com.
    path is like if you want it only in a certain folder (would be good if you had several quizzes, so like /1/ could be set to having taken the quiz, but the folder /2/ wouldn't be... etc.). Ignore this, too, probably.

    So... all you need....
    setcookie('cookiename','value','expires')

    So.... do you even need to set an expiration time?
    If so, then use time() and add seconds til you want it to end (like 3600 would be an hour after the cookie is first set. time() outputs the current time).


    As for cookiename and value... easy.

    'mypage' and 'visited'

    Or whatever.

    You can later get this (but only on the next page... you can't send and recieve a cookie in one page load, I don't think) in your PHP script like so:
    $_COOKIE['name']

    So...
    to continue with above--
    if ($_COOKIE['mypage'] == 'visited') { echo "You have already been here!"; }
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2006
    Posts
    198
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the tips. That all makes good sense.

    I'm still experiencing the problem. I've got a confusing mix of Javascript that I don't full understand and PHP that I've never used before overlaying on the page. So it's hard to know exactly where the problem lies.

    I'm going to try to re-write it all with PHP and they I'll post it up if it's still not working.

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
  •