Thread: cookie problem

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    49
    Rep Power
    14
    i always facing a problem in setting the cookie. the cookie that i set always return a empty value.
    my code is as follw:
    setcookie("weather", $location, time()+14400);
    where the value of location is the value from selection list.
    can somebody help me to solve this problem?
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    setcookie("weather", $location, time()+14400);
    where the value of location is the value from selection list.


    just check it out wether location value is passing to the function or not.

    <?
    if (!isset($location)){
    $location="india";
    }
    setcookie("weather", $location, time()+14400);

    ?>

    you can check it out wether your cookie is set up or not using ..

    <?
    if(isset($weather))
    {
    print $weather. "<BR>n";
    }
    else
    { print "No cookie has been set";

    }
    ?>



    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    You do not have to specify the time... just test it this way first...

    setcookie("weather", "india");


    on submit, check to see if it was set ...

    echo $weather;

    Note: Cookies are directory sensitive in my experience with php.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    32
    Rep Power
    14
    To expand upon what the previous member mentioned vaguely, you'd have to set the directory for your cookie if you want it to appear over your entire website. To set your cookie, you'd use:

    setcookie("weather",$location,time()+14400,"/","www.myurl.com");

    If you don't add in the last two variables, the cookie won't be recognized anywhere but in the directory you set it in...perhaps this is your problem. Not enough detail to determine. :-/

Similar Threads

  1. Placing user-entered data into cookie
    By Tyrone in forum Perl Programming
    Replies: 2
    Last Post: February 17th, 2004, 04:31 PM
  2. Session Cookie Problem?
    By JHarp in forum PHP Development
    Replies: 1
    Last Post: February 17th, 2004, 01:43 PM
  3. re: Cookie - serves only one directory?
    By ellen in forum PHP Development
    Replies: 1
    Last Post: February 16th, 2004, 11:59 PM
  4. will PHP write over the same cookie?
    By xpatriot in forum PHP Development
    Replies: 5
    Last Post: February 2nd, 2004, 08:59 AM
  5. Odd COOKIE problem
    By rwreid in forum PHP Development
    Replies: 3
    Last Post: January 28th, 2004, 01:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo