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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:11:04+00:00 2026-05-18T01:11:04+00:00

I wrote a little PHP script below to demonstrate my question. Run the code

  • 0

I wrote a little PHP script below to demonstrate my question. Run the code below like this: http://localhost/test.php?test=10, then run http://localhost/test.php?test=11, then http://localhost/test.php?test=12, etc. You will see that the number echo’ed to your screen is always 1 digit behind the url number?! Maybe because I cant a cookie and immediately read the same cookie?


//If query string has $test, store in session, and cookie for later. 
if($_GET[test]){
  $_SESSION['test'] = $_GET[test];
  setcookie("test", $_GET[test], time()+60*60*24*30*12*10); //10 years
}

//If user comes back later, then get $test from cookie
if (isset($_COOKIE["test"])){
  $_SESSION['test'] = $_COOKIE["test"];
}

echo "session test: " . $_SESSION['test'];

Later, I solved the problem with the following code, but solving it is not good enough, I want to know WHY this happened!

This solved it:


if($_GET[cid]){
  setcookie("campaignid", $_GET[cid], time()+60*60*24*30*12*10); //10 years
  $_SESSION['campaignid'] = $_GET[cid];
}elseif (isset($_COOKIE["campaignid"])){
  $_SESSION['campaignid'] = $_COOKIE["campaignid"];
}

  • 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-18T01:11:05+00:00Added an answer on May 18, 2026 at 1:11 am

    Maybe because I cant a cookie and immediately read the same cookie?

    Exactly. The cookie you sent is available in $_COOKIE array only in the next request, because the $_COOKIE superglobal array is filled with the data, that comes in the client’s request. And at first request it is nothing.

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

Sidebar

Related Questions

I've bumped into a strange problem. I wrote a little daemon in Perl which
referring to this question , I've decided to duplicate the tables every year, creating
I have a little python script that pulls emails from a POP mail address
[Edit] I have reedited the previous question - since I had misunderstood what was
Currently I have a custom tool which generates vanilla-SQL (only using standard SQL), from
I am looking for a form class that: Is standalone/doesnt need a framework to
we're starting to build a web app. My colleague is developing on linux, and
First of all, I understand in 90% of applications the performance difference is completely
I have a pretty long SQL query that I use to, for all of
I'm in the process of updating some old CSS files in our systems, and

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.