Results 1 to 4 of 4

Thread: cookies

  1. #1
    Join Date
    Dec 2006
    Posts
    74
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default cookies

    How do i create a cookie that will hide a section on my page when the cookie is set and show the section when the cookie deleted?

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Use ifs and elses...

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yeah, just do this:
    PHP Code:
    <?php

    if (isset($_COOKIE['cookiename'])) {
        
    // what you want to have if cookie is set
    } else {
        
    // what you want to have if cookie is not set
    }

    ?>
    Hope that explains it
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Then to set the cookie...

    $coo = setcookie("cookiename","value",time()+expire time,"/","domain");
    if (!$coo) {echo "Failed";} else {echo "Successful";}

    * expires in- 3600*12 = 12 hours, 3600*24*7 = 7 days, 3600*24*365 = 365 days
    * Domain - your web address: www.domain.com
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

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
  •