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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts

    setting a cookie with php..

    I've been trying to set a cookie, and so far unsuccessful, every time I visit the page I open cookie editor addon in firefox and I don't see the cookie, here's what I'm using to set the cookie

    PHP Code:
    setcookie("site_user"$u_namedate() + 31536000"/"); 
    could anyone advise if this is the correct way to do this?

    thanks

    www.pctechtips.org

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Because you're using "date()" and not "time()"
    e.g.
    PHP Code:
    setcookie("site_user"$u_nametime() + 31536000"/"); 
    plus I'm pretty sure "/" is on by default.

    Edit: And if $u_name isn't defined the cookie won't be set.. so ensure it's set.

  • Users who have thanked Iszak for this post:

    mia_tech (08-08-2008)

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Iszak View Post
    Because you're using "date()" and not "time()"
    e.g.
    PHP Code:
    setcookie("site_user"$u_nametime() + 31536000"/"); 
    plus I'm pretty sure "/" is on by default.

    Edit: And if $u_name isn't defined the cookie won't be set.. so ensure it's set.
    you hit it right on the head!... I don't know what made me use date() instead of time(), but as soon as I changed it... it worked!

    thanks

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts
    in my cookie code I'm setting the name of the cookie to equal the username; how could generate an md5 hash of this username instead of just put the plain text of the username in the cookie?...

    thanks


    www.pctechtips.org

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    setcookie("site_user"md5($u_name), time() + 31536000"/"); 

  • Users who have thanked Nightfire for this post:

    mia_tech (08-08-2008)

  • #6
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts
    thanks


  •  

    Posting Permissions

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