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

  • Home
  • SEARCH
  • 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 705967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:06:49+00:00 2026-05-14T04:06:49+00:00

I wonder if someone can help shed some light on this: I drop a

  • 0

I wonder if someone can help shed some light on this:

I drop a cookie if a user arrives to the site with a specific key/value in query string. i.e.: http://www.somesite.com?key=hmm01

The cookie code exists at top of the template before <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ) :

<?php
header("Content-Type: text/html; charset=utf-8");
ob_start();
if (isset($_GET['key'])) {
setcookie("cookname", $_GET['key'], time()+2592000); /* Expires in a month */
}
ob_end_flush();
?>

On the same page though within the : I have the following php code that sniffs the cookie and outputs some text:

`

switch ($cookievalue)
{
case hmm01:
echo “abc”;
break;
case hmm02:
echo “def”;
break;
case hmm03:
echo “ghi”;
break;
default:
echo “hello”;
}
?>`

— Problem is when the user first arrives the sniffer script doesn’t detect the cookie and outputs the default text: hello
Only when user refreshes page or navigates to a different page does the sniffer detect the cookie.

Any ideas on how to drop the cookie and output the correct text without a page refresh?

Many thanks.

  • 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-14T04:06:50+00:00Added an answer on May 14, 2026 at 4:06 am

    Simply check $_GET for the first time:

    if(isset($_GET['key'])) { $cookievalue = $_GET['key']; }
    if(isset($_COOKIE['cookname'])) { $cookievalue = $_COOKIE['cookname']; }
    
    switch ($cookievalue) { case hmm01: echo "abc"; break; case hmm02: echo "def"; break; case hmm03: echo "ghi"; break; default: echo "hello"; } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone can help me please. I've put together this page which
I wonder whether someone can help me please. I've created this form which allows
after reading this question i wonder if someone can help me understand how to
I wonder if someone can help me with this. I have a LINQ query
I wonder if someone here can help me figure out this problem. I need
wonder whether someone can help me with the following one... I have a struct
I wonder if someone can help me. I'm trying to add a reference to
I wonder if someone can help me. I'm trying to display a toast element
I wonder if someone can help: Long story short, I'm using MSSQL2005 to build

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.