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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:43:56+00:00 2026-05-22T00:43:56+00:00

I’m setting a cookie on localhost with the following syntax setcookie(testCookie , hello cookie,

  • 0

I’m setting a cookie on localhost with the following syntax

setcookie("testCookie ", "hello cookie", false, "/", false);

The problem is the first time I visit the page the cookie is created and firebug shows

Cookie testCookie added.  hello cookie

But it does not read the value. If I refresh the page, the value is read and fire bug shows

Cookie testCookie changed.  hello cookie

How can I get the value of the cookie to be read the first time the page is loaded?

  • 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-22T00:43:57+00:00Added an answer on May 22, 2026 at 12:43 am

    As I put in my comment, from your description (although fairly vague and not too understandable), I think the issue may be that you’re trying to read the cookie before it’s sent to the server.

    The way a cookie works is as follows:

    1. You make a request
    2. Server SENDS cookie header back to client
    3. Page loads – Cookie is NOT visible to PHP on this page load
    4. Refresh
    5. Client SENDS cookie header to server
    6. Server RECEIVES cookie header thus PHP can read it
    7. Page loads – Cookie IS visible here.

    If you haven’t tried already, refresh again!

    Since you want to read it at the same time you’re setting it, just store the value you’re setting and use that. Alternatively (although this is untested), you could manually set it in the $_COOKIE array.

    So something like this:

    setcookie("helloworld", .. );
    $_COOKIE['helloworld'] = $value;
    

    Then you can read it normally. Note that I wouldn’t really recommend overriding the value of an automatic superglobal (same goes for $_REQUEST, $_POST, $_GET, etc.), and would instead suggest that you just store the value you’re setting and use that.


    Another approach would be to use a form of “gateway”, meaning you’d set the cookie on a gateway page, which will then continue to redirect you to the next page.

    For example, say your flow was as follows: login.php -> account.php. Rather than POST’ing your login form straight to account.php you have 2 options.

    Opt 1: POST back to login.php, set the cookie, and then redirect to account.php.
    Opt 2: Have a gateway, such as logincheck.php, POST through to that, set the cookie, and then redirect to account.php.

    This way, account.php can always see your cookie.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having 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.