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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:37+00:00 2026-06-11T16:10:37+00:00

I am facing a difficulty in understanding the usage of cookies in PHP, Please

  • 0

I am facing a difficulty in understanding the usage of cookies in PHP,
Please consider the following code snippet

 public function preExecute() {

setcookie("testCookie", "Hello123", time() + 31536000, "/", WebServer::getServerName());
echo "Before Value of cookine in decommission::".$_COOKIE["testCookie"];
setcookie("testCookie", "Hello456", time() + 31536000, "/", WebServer::getServerName());
echo "After Value of cookine in decommission::".$_COOKIE["testCookie"];
}

The output that i am expecting for this code

Before Value of cookine in decommission::Hello123

After Value of cookine in decommission::Hello456

But the output i am getting for the above code snippet is

Before Value of cookine in decommission::Hello456

After Value of cookine in decommission::Hello456

Will appreciate if someone explain me the working, i have gone through resources available in internet, but still i am not clear.

Thanks in advance.

  • 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-11T16:10:38+00:00Added an answer on June 11, 2026 at 4:10 pm

    $_COOKIE holds the cookies that have been received in the current request. It is not automatically updated when you call setcookie to set cookies in your response. The cookies you set via setcookie will only appear in $_COOKIE on the next request, when the cookies are sent back to the server.

    So what you’re seeing is that the second cookie overwrites the first, so only the later value is sent back to the server. I’ll guess you have refreshed the page several times already, so you’re seeing the cookie. If you clean your cookies and run this again, on the first try you won’t see any output, because $_COOKIE is empty and stays empty for the whole request, no matter how often you call setcookie.

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

Sidebar

Related Questions

Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
I'm facing difficulty in understanding source and header files stuff. Suppose 1)I have a
I am facing difficulty understanding references in perl. Here is a short perl script
I am facing extreme difficulty digesting the concepts of assembly language programming. I am
Im facing the following problem: I want to integrate the mercurial hash into my
I am trying to create Jqplot bar charts and facing difficulty in creating multidimensional
I'm facing difficulty when creating some kind of a report in vfp. I created
I am facing difficulty to handle my own exception from Anonymous Inner class which
I am trying to create Jqplot bar charts and facing difficulty in creating multidimensional

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.