Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:48:26+00:00 2026-06-08T12:48:26+00:00

I’m having a cookie situation, where my cookies would store a color name or

  • 0

I’m having a cookie situation, where my cookies would store a color name or nothing at all. So let’s explain it this way. My cookies are related to the look of my website, my website has 3 looks:

  • Normal (with no cookie at all)
  • Grey (with a cookie set to ‘imgit_style’ with value “grey”)
  • Inverted (with cookie set to ‘imgit_style’ with value “inverted”)

I have 3 buttons which trigger the styles to switch. The first button is for Normal, it deletes the cookie and makes the look normal.

The second button is for Grey, it creates the cookie with name ‘imgit_style’ and adds a value to it – “grey”.

These two work completely fine with each other, but when setting the Inverted cookie it wont work! It just gets deleted when I click the third button which should actually replace Grey (if it’s set) with Inverted OR create the cookie if it was unset by the first button.

Hope I was clear enough. Here is my code:

Styles.php

<?php
$style = '';
if (!isset($_COOKIE['imgit_style']))
{
    if (isset($_POST['green']))
    {
        setcookie('imgit_style', '', time()-31556952);
        $style = '';
    }
    if (isset($_POST['grey']))
    {
        setcookie('imgit_style', 'grey', time()+31556952);
        header('Location: ' . $home_action);
    }
    if (isset($_POST['inverted']))
    {
        setcookie('imgit_style', 'inverted', time()+31556952);
        header('Location: ' . $home_action);
    }
}
else if (isset($_COOKIE['imgit_style']))
{   
    $style =  '_' . $_COOKIE['imgit_style'];
    if (isset($_POST['green']) && $_COOKIE['imgit_style'] == 'grey' || $_COOKIE['imgit_style'] == 'inverted')
    {
        setcookie('imgit_style', '', time()-31556952);
        $style = '';
        header('Location: ' . $home_action);
    }
    if (isset($_POST['grey']))
    {
        if ($_COOKIE['imgit_style'] == 'inverted')
        {
            setcookie('imgit_style', '', time()-31556952);
            if (!isset($_COOKIE['imgit_style']))
            {
                setcookie('imgit_style', 'grey', time()+31556952);
                header('Location: ' . $home_action);
            }
        }
    }
    if (isset($_POST['inverted']))
    {
        if ($_COOKIE['imgit_style'] == 'grey')
        {
            setcookie('imgit_style', '', time()-31556952);
            if (!isset($_COOKIE['imgit_style']))
            {
                setcookie('imgit_style', 'inverted', time()+31556952);
                header('Location: ' . $home_action);
            }
        }
    }
}
?>

header.php

<!DOCTYPE HTML>
<html>
<head>
<?php include('styles.php'); ?>
<title>IMGit.org - the image host</title>

<link rel="stylesheet" type="text/css" href="css/<?php echo 'style' . $style . '.css'; ?>" media="screen" />
<link rel="icon" href="css/images/<?php echo 'favicon' . $style . '.png'; ?>" type="image/x-icon" />
<link rel="shortcut icon" href="css/images/<?php echo 'favicon' . $style . '.png'; ?>" type="image/x-icon" />
</head>

<body>
<div class="style-switcher">
<form action="" method="post">
<table>
    <tr>
        <td>
            <span class="normal" style="vertical-align: text-top;">Switch style:</span>
            <input type="submit" name="green" class="style_green-button" value="green" />
            <input type="submit" name="grey" class="style_grey-button" value="grey" />
            <input type="submit" name="inverted" class="style_inverted-button" value="inverted" />
        </td>
    </tr>
</table>
</form>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:48:27+00:00Added an answer on June 8, 2026 at 12:48 pm

    The problem looks to be that although you call setcookie() blank out the cookie value $_COOKIE still holds that value for this request. Its contents would not change until the page is reloaded. So you go on to check !isset($_COOKIE['imgit_style']), but that value will still be set unless you explicitly unset it.

    if (isset($_POST['grey']))
    {
        if ($_COOKIE['imgit_style'] == 'inverted')
        {
            // No need to unset the old one, just overwrite the new one
            // setcookie('imgit_style', '', time()-31556952);
            setcookie('imgit_style', 'grey', time()+31556952);
            header('Location: ' . $home_action);
        }
     }
     if (isset($_POST['inverted']))
     {
        if ($_COOKIE['imgit_style'] == 'grey')
        {
            // No need to unset the old one, just overwrite the new one
            // setcookie('imgit_style', '', time()-31556952);
            setcookie('imgit_style', 'inverted', time()+31556952);
            header('Location: ' . $home_action);
        }
     }
    

    Update

    This may be the issue… You have no parenthetical groups to logically group this if() statement:

    if (isset($_POST['green']) && $_COOKIE['imgit_style'] == 'grey' || $_COOKIE['imgit_style'] == 'inverted')
    

    What happens here is that anytime $_COOKIE['imgit_style'] == 'inverted', even if $_POST['green'] isn’t set, the subsequent code runs and removes the cookie. Looks like you want instead to group the ('grey' || 'inverted') together:

    if (isset($_POST['green']) && ($_COOKIE['imgit_style'] == 'grey' || $_COOKIE['imgit_style'] == 'inverted'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.