SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Owerwriting cookie

    I'm trying to set a cookie based on input from a form. I have tried using "switch" as you can see below. But I can't seem to delete or owerwrite the old cookie. It sets the first cookie allright, I just can't change it lateron.
    Anyone got some ideas on how to do this, either by altering this code or doing it in another way..
    PHP Code:
     <?php
       
    switch($skin) {
              case 
    "1";{
              
    $c ='';
              
    setcookie("skin"$c);
              
    $s '1'
              
    setcookie("skin"$stime()+60*60*24*30"/");
              }
              break; 
              case 
    "2";{
              
    $c ='';
              
    setcookie("skin"$c);
              
    $s '2'
              
    setcookie("skin"$stime()+60*60*24*30"/");
              }
              break; 
              case 
    "3";{
             
    $c ='';
              
    setcookie("skin"$c);
              
    $s '3'
              
    setcookie("skin"$stime()+60*60*24*30"/");
              }
              break; 
              case 
    "4";{
             
    $c ='';
              
    setcookie("skin"$c);
              
    $s '4'
              
    setcookie("skin"$stime()+60*60*24*30"/");
              }
              break; 
              default:{
             
    $c ='';
              
    setcookie("skin"$c);
              
    $s '1'
              
    setcookie("skin"$stime()+60*60*24*30"/");
                     }
          }
    if (isset(
    $skin)) 
    $value $_COOKIE['skin'];
    include (
    "skins/skin$value.htm");
    $header "header$value.jpg";
      }
      
    ?>
    All help is appreciated..

  2. #2
    Setting up a connection... mgyth's Avatar
    Join Date
    Nov 2004
    Location
    Mosjøen - Norway
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK,
    The thing is that when i set the variable $skin in the switch statement I had used the same variable name for both the switch variable and the cookie variable, so when the switch statement got the $skin variable from the form it was overwritten by the cookie variable before it could set a new cookie, thus setting a new cookie with the same value as the old one. That simple, hu?.
    now I have changed the switch variable and it works fine.
    Exept that I need to reload the page after setting the cookie, and when using the:
    PHP Code:
    header("Location: $PHP_SELF"); 
    statement it seems to reload the folder the page is in as a site.
    example:
    the folder the page is in is: phpt/
    so the site reloades as: www.phpt.com witch has obvious drawbacks.
    Anyway i'm sure i'll figure it out somehow.


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
  •