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 7059015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:10:54+00:00 2026-05-28T04:10:54+00:00

i have this code im trying to do for a type of cache system

  • 0

i have this code im trying to do for a type of cache system so it remembers the city the user has selected. if the user has selected a city it stores it in sessions and cookies, and will automatically redirect them to the city page if they’ve selected it before.

sessions work fine, but it doesn’t seem to be setting the cookie to an empty value if the $_GET[‘city’] variable is empty…

heres my code:

function gen_url ($city)
{
    $url = 'http://www.mysite.com';

    if (!empty($city)) $url .= "/c-$city";

    return $url;
}

function set_cache ($variable, $value)
{
    $_SESSION[$variable] = $value;
    setcookie($variable, $value, time() + 31536000);
}

$redirect = false;
$redirect_array['city'] = '';

if (!empty($_GET['city']))
{
    $sql = mysql_query("select * from `cities` where `slug`='".mysql_real_escape_string($_GET['city'])."'");

    if (mysql_num_rows($sql) != 0)
    {
        while ($row = mysql_fetch_assoc($sql))
        {
            foreach ($row as $k => $v)
                $city[$k] = $v;
        }

        $redirect_array['city'] = $city['slug'];
    }
    else
    {
        $redirect = true;
    }
}   

if ($redirect)
{
    header('Location: '.gen_url($redirect_array['city']);
    die();
}

set_cache('city', $redirect_array['city']);
  • 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-05-28T04:10:54+00:00Added an answer on May 28, 2026 at 4:10 am

    You can’t set a cookie with an empty string as it will delete the cookie.

    From the docs:

    If the value argument is an empty string, or FALSE, and all other
    arguments match a previous call to setcookie, then the cookie with the
    specified name will be deleted from the remote client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my ASP.NET application written in C# that is trying
I'm extremely new to JS and have this code that I'm trying to tweak.
I am trying to compare two dates. I have this code which I thought
I have this piece of code I'm trying to get to display but no
I have got this code and I am trying to understand the convention followed,
I have this php code, with which I am trying to generate a popup
I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code
All, I am trying to code a Connect4 game. For this, I have created
I have this code in the view to display datepicker for input type.. Problem
Basically I have this code. I am trying to simply update a div but

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.