Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cookie only working in one directory.

    I have a cookie set with these (very limited) parameters
    PHP Code:
    setcookie ('username2'$username); 
    Currently if I call that via PHP
    (
    PHP Code:
    echo $_COOKIE["username2"]; 
    )
    , it only works in my "/login/" directory and not my main directory.
    What addl parameters do I need to add to that so it will work everywhere?


    (I bet this is something very simple)

    Edit: Tried
    PHP Code:
    setcookie('username2'$username,  '/''MyWebsite.com'); 
    didn't work.
    Last edited by Crazydog; 11-09-2006 at 07:54 AM.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    which directory is it being set it try
    PHP Code:
    $value "Test cookie";
    setcookie("TestCookie"$valuetime()+60*60*24*30);  /* expire in 30 days */
    //or
    setcookie('TestCookie'$valuetime()+3600'/''.mysite.com');  /* expire in 1 hour and set for all directory's on your web server and all subdomains*/ 

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    alright, that works..

    but I've been having trouble finding out how to set the time syntax to expire at end of session without not including it..

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    just leave it out?

    ,,

    nothing between the commas?

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    See if I do
    PHP Code:
    setcookie ('username2'$username, , '/''.mysite.org'); 
    I get
    Parse error: syntax error, unexpected ',' on line 44

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:

    setcookie 
    ('username2'$username'''/''.mysite.org'); 
    there needs to be info to tell php your not limiting it
    if you leave
    setcookie ('username2', $username, , , '.mysite.com');
    its not gonna know the directory or time to set
    make sense?

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    oops ... Rafiki is right ...

    I think I forgot the ,' ',


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •