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 14 of 14
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clear all cookies then set a cookie

    How can I in an if statement

    1. clear all cookies previously set
    and then
    2. set a cookie

    BTW, I know how to do #2.....


    Thanks
    Last edited by SDP2006; 09-20-2003 at 03:28 AM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    if(isset($_COOKIE['name'])){
      
    setcookie ("name"""time() - 3600);

    This will set the expiry time in the past, making the cookie wipe itself out.

    http://uk.php.net/manual/en/function.setcookie.php

    If you check the manual before you post, you'll get your answer alot faster

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, what I am doing is setting a cookie for the preference of style on my site. What is doing is setting a cookie, and I guess its not overwriting it....here's my script
    PHP Code:
    //This is the form action
    <?php
    $value 
    $_POST['colors'];
    $blue "Royale Blue";
    $teal "Teal";
    $green "Hunter Green";
    $maroon "Maroon";
    $grey "Grey";

    if (
    $value == $blue){
    setcookie("blue",time()+3600);}

    elseif (
    $value == $teal){
    setcookie("teal",time()+3600);}

    elseif (
    $value == $green){
    setcookie("green",time()+3600);}

    elseif (
    $value == $maroon){
    setcookie("maroon",time()+3600);}

    elseif (
    $value == $grey){
    setcookie("grey",time()+3600);}

    else
    {
    echo 
    "Nothing isset!";
    }

    ?>
    and heres what checks
    PHP Code:
    //Checks for cookie, then echos a style sheet
    <?php
    if (isset($_COOKIE['blue'])){
    echo 
    "<link rel=stylesheet href=styleblue.css type=text/css>";}

    elseif (isset(
    $_COOKIE['teal'])){
    echo 
    "<link rel=stylesheet href=styleteal.css type=text/css>";}

    elseif (isset(
    $_COOKIE['green'])){
    echo 
    "<link rel=stylesheet href=stylegreen.css type=text/css>";}

    elseif (isset(
    $_COOKIE['maroon'])){
    echo 
    "<link rel=stylesheet href=stylemaroon.css type=text/css>";}

    elseif (isset(
    $_COOKIE['grey'])){
    echo 
    "<link rel=stylesheet href=stylegrey.css type=text/css>";}

    else {echo 
    "<link rel=tylesheet href=style.css type=text/css>";}
    ?>
    It will work the first or couple of times you select a different color, but then after the first or second time, it wont do it until the cookie times out.....
    If you need an example of what I am trying to accomplish, visit http://www.net-riches.com/includes/c...s.php?cat=home and scroll all the way to the bottom

    Thanks
    Last edited by SDP2006; 09-20-2003 at 04:49 AM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Help anyone?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anybody?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Why not save yourself time and only use one cookie instead of 5 or so? Just change the value in the cookie to the colour you want. If the cookie's set, echo the cookie's value into the stylesheet link, if it's not set, load the default style

  • #7
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you show me an example, Nightfire?

    Thanks a million...you guys are great
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    // set cookie from a link  page.php?styles=blue
    $value $_GET['styles'];

    setcookie("stylesheet",$value,time()+3600);

    // check for cookie and show correct stylesheet

    if(isset($_COOKIE['stylesheet'])){
      
    $link $_COOKIE['stylesheet'].'css';
    }else{
      
    $link "defaultstyle.css";
    }

    echo 
    '<link rel="stylesheet" type="text/css" href="'.$link.'" />'

  • #9
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've seen something before like

    if (isset($_COOKIE['name'])){
    echo "<link rel=stylesheet href=$style>";

    not using the $_GET['method'];

    and $style was set in the cookie....how can I do that?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #10
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, for some reason it is echoing stylecss instead of style.css....
    Here is the code
    PHP Code:
    <?php
    if(isset($_COOKIE['stylesheet'])){
      
    $link $_COOKIE['stylesheet'].'.css';
    }else{
      
    $link "style.css";
    }
    echo 
    '<link rel=stylesheet type=text/css href='.$link'>';
    ?>
    Last edited by SDP2006; 09-20-2003 at 10:47 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #11
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    echo '<link rel=stylesheet type=text/css href='.$link.'>';

    You're missing a . after $link

  • #12
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works wonderful! Thanks so much guys!!
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #13
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Glad to have helped


  •  

    Posting Permissions

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