SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Cookie problems

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie problems

    I am using the function below to check if a cookie exists and if it doesnt it sets one. However it isn't setting the cookie but it does return the session_id. Any ideas?

    function GetEnqId()
    {

    if(isset($_COOKIE["EnqId"]))
    {
    return $_COOKIE["EnqId"];
    }
    else
    {

    session_start();
    setcookie("EnqId", session_id(), time() + ((3600 * 24) * 30));
    return session_id();
    }
    }

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you call GetEnqId() before you send any output?

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drzoid
    Are you sure you call GetEnqId() before you send any output?

    Yup!

    I call the function within a select statement.

    $result = mysql_query("select count(*) from enquiry where cookieId = '" . GetEnqId() . "' and PropID = $PropID");

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Pittsburgh
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe the time is getting messed up

    try

    setcookie("EnqId", session_id(), )time() + ((3600 * 24) * 30))); shouldnt make a difference but who knows

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but no change

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried setting the same cookie outside of the function and it worked. But why won't it work inside the function

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Pittsburgh
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i bet $_COOKIE["EnqId"] is returning true, try clearing the cookie and see if its sets the new one

  8. #8
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I cleared all my cookies just incase it was conflicting with anything else. It works now.


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
  •