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 11 of 11
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question cookie does not last for long...

    hey all,, first i want you to go to this site,, www.7des.com

    and just switch pages fast,, and try to change the styles,,,

    the chosen style well not last for the whole season,, and also once you chose a style it will not set untill the page is refreshed,,

    the code i have is this...

    PHP Code:
    <? 
    if (isset($_POST['style']))  

      
    $style_sheet $_POST['style'];  
    } else {  
      
    $style_sheet "default";  


    setcookie('css',$style_sheet,time()+999999999);  

    ?>
    (the dropdown box is set to do the action in index.php where the top code is placed at the very top)

    thanx alot

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    how does your code choose which stylesheet to use?

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The larger problem I'm having is getting it to 'stick' on a theme. Its fine once its changed, some links will hold, others will not.
    I don't recommend that you define it just with cookies, allow it on there nonetheless as this way the user can have it stick for them. Otherwise, your looking at using sessions.
    Now, without knowing what you have set within your tracking I cannot tell you the best way of doing this. From the given code that we have the only tracking I can see thats being used is to set a cookie, not to read information after the fact. As I mentioned, cookies are also unreliable for generating information.
    What I would do is like so:
    PHP Code:
    <?php
    ini_set
    (session.use_trans_sid'1');  // Think this is right, I always have them enabled so I don't need to set it (try it without this line first, with cookies off)
    session_start();

    // Strongly recommend the use of this to confirm that the user isn't trying to pass their own data:
    $allowed_styles = array(
         
    'red',
         
    'blue',
         
    'green'
    ); 

    if (!isset(
    $_SESSION['style']))
    {
         
    // Style is currently empty, let us check the request methods:
         
    if (!isset($_POST['style']) AND isset($_COOKIE['style']) && in_array($_COOKIE['style'], $allowed_styles))
         {
              
    // Cookie is set for this style:
              
    $_SESSION['style'] = addslashes($_COOKIE['style']);
         }
         else if (isset(
    $_POST['style']) && in_array($_POST['style'], $allowed_styles))
         {
              
    // Cookies not set (or possibly set due to first condition) however post is set:
              
    $_SESSION['style'] = addslashes($_POST['style']);
         }
         else
         {
              
    // Neither cookies, sessions, post, or allowed data is set, let us default it:
              
    $_SESSION['style'] = 'default';
         }
    }

    setcookie('css'$_SESSION['style'], time()+999999);

    // Here, you will need to have whatever code to identify the page's css type
    Just change whatever you are using to identify the css type from $_COOKIE to $_SESSION and it should work no problem for you. Of course, I haven't tested this though, so give it a shot somewhere where it won't cause you headaches first :P

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    seeitseloutions,, i don't know what you mean sorry

    and Fou-Lu

    it does not seem to work,, same thing happens the style keeps changing on it's own the whole time,,, here is the code for index.php

    PHP Code:
    <? 
    if (isset($_POST['style']))  

      
    $style_sheet $_POST['style'];  
    } else {  
      
    $style_sheet "default";  


    setcookie('css',$style_sheet,time()+999999999);  

    ?> 

    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <?php 
        $style_sheet 
    = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default'
        echo 
    '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">'
    ?>
    <title>7Designs Home</title> 
    </head>

    <body>
    <div align="center">
        <table border="0" cellpadding="0" cellspacing="0" width="800" id="table1" class="out" height="520">
            <tr>
                <td height="100" class="banner" colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td width="800" colspan="2">
                <?php include("includes/head.php"?></td>
            </tr>
            <tr>
                <td width="150" valign="top"><?php include("includes/links.php")?></td>
                <td width="650" align="center" class="content_container"><?php echo $lang['welcome'?> <table border="0" cellpadding="0" cellspacing="0" width="600" id="table2" height="350">
                    <tr>
                        <td>
                        <div align="center">
                            <table border="0" cellpadding="0" cellspacing="0" width="353" height="300" id="table3" class="content">
                                <tr>
                                    <td class="content_title" height="21">What's New at 7Designs</td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                    <ul>
                                        <li>BETA test of the new version</li>
                                        <li>Questions section is open for any 
                                        question you have</li>
                                        <li>Version 5 was Released after a few weeks 
                                        of work </li>
                                    </ul>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        </td>
                        <td>
                        <div align="center">
                            <table border="0" cellpadding="0" cellspacing="0" width="200" height="300" id="table4" class="content">
                                <tr>
                                    <td class="content_title" height="21">Latest 
                                    Topic/News at the <a href="/forum" class="cnt_t">Forums</a></td>
                                </tr>
                                <tr>
                                    <td valign="top">Forum icon Battle in the battle 
                                    room<p>Shoutbox added</p>
                                    <p>New background displays</p>
                                    <p>New signatures in showcase</td>
                                </tr>
                            </table>
                        </div>
                        </td>
                    </tr>
                </table>
                </td>
            </tr>
        </table>
    </div>

    <p align="center"><span class="tail"><?php include("includes/tail.php"?></span></p>

    </body>

    </html>

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try this. It will just replace your code up until the same line

    PHP Code:
    <?  
    if (isset($_POST['style']))   
    {  
      
    $style_sheet $_POST['style'];   
    } else {  
      
    $style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';  
    }

    setcookie('css',$style_sheet,time()+999999999); 

    ?>  

    <html> 

    <head> 
    <meta http-equiv="Content-Language" content="en-us"> 
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
    <?php    
        
    echo '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">';  
    ?>

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The only problem I see is its still reliant on cookies. I also goofed with my code above there as well, my setcookie name should have been 'style' not 'css'. After that, access for it would be set via $_SESSION['style'] instead of $_COOKIE['css'].
    The problem is, assuming this is the same code on all of your pages, you are attempting to grab style from a post variable everytime, otherwise its set to default. Which is why your pages keep changing back. $_POST data does not send from page to page via links.

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    That's what my code fixes.

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    very well done Fou-Lu & SeeIT Solutions

    i can't thank you enough,,, so there is one thing fixed

    the CSS changes right away!

    www.7des.com

    now another problem is still in the way,, the style swiched back to blue after 2 pages...

    it will not stay that for the whole season.. you can check your self

  • #9
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It seems as thought the projects page doesnt have the right code in it.

    Make sure you put that code I gave you on every page.

  • #10
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ohhhhhhh i see,,, i will try now,,,

  • #11
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect perfect perfect

    its working and it stays in each page!

    even when i leave the site at (green) and open the browser again it still stays at green

    so the cookie is perfect

    thank you all of you so much


  •  

    Posting Permissions

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