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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:31:49+00:00 2026-06-09T11:31:49+00:00

I am using a $_COOKIE[array] in order to save data for a single input.

  • 0

I am using a $_COOKIE[array] in order to save data for a single input. This input will only submit if the user entered the same value twice. For instance, if they submitted apple, then orange, then banana, then apple, the form would submit on the second appearance of “apple”.

I read [this tutorial](
http://phpprogramming.wordpress.com/2007/03/06/php-cookies-tutorial-and-examples/).

for ($i = 1; $i < 10; $i++) {
    if (!isset($_COOKIE[$i])) {
        setcookie("query" . [$i],$query,time()+604800,"/");
        break1;
    }
}
foreach ($_COOKIE["query"] as $key => $value) {
    echo "$key:$value";
}

I believe it might be a syntax error since I get:

Warning: Invalid argument supplied for foreach()

If you know a better way (can’t be mySQL), then please let me know!

  • 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-09T11:31:50+00:00Added an answer on June 9, 2026 at 11:31 am

    $_COOKIE[‘query’] can not store an array. This is also why you get an error when you try to use it in the foreach. You could serialize your array before saving it though. Something like this

    $array = array();
    for ($i = 1; $i < 10; $i++) {
        $array[] = $i;
    }
    setcookie("query",urlencode(serialize($array)),time()+604800,"/");
    
    $query = unserialize(urldecode($_COOKIE['query']));
    foreach ($query as $key => $value) {
        echo "$key:$value";
    }
    

    also have a look at this post update cookie value in php for the expalanation why the urlencode / urldecode is used

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

Sidebar

Related Questions

I'm using this code, but it returns empty data array. My access_token has all
I am currently using this process to Sanitize/Filter comment entered by users -> This
I'm using the following functions to set an array of values in a cookie
I'm opening a new thread based on this how to store an array in
I am using PHP5 and CodeIgniter and I am trying to implement a single-sign
This is royally annoying me at the moment: Consider an array of 2 values:
jqGrid tree nodes are read from server using json data. Click in node reads
I am using Facebook PHP SDK to authenticate the user. After generating the LoginUrl
I am trying to automatically fill a form from cookie data if the user
I'm using CookieJar to read and write an Array of Objects to a cookie.

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.