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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:58:25+00:00 2026-06-07T01:58:25+00:00

I need to store some array data in a cookie and I have been

  • 0

I need to store some array data in a cookie and I have been researching the best way to do it, many people seem to say using serialize is the way to go, but then in this thread:

PHP how to stringify array and store in cookie

..someone suggested against using it as “serialize will call constructor of a serialized class. This is bad because it can cause code execution.”

So I’m wondering what other options I have? What about base64_encode?

I can’t use sessions as I need to retain the data AFTER the browser is closed; though I am also worried about Cookies 4KB limit.

FWIW I am storing shopping cart data of what is stored in someones cart, it needs to be loaded back in their cart when they come back.

  • 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-07T01:58:27+00:00Added an answer on June 7, 2026 at 1:58 am

    How about generating a unique ID, storing it in a cookie, and storing your serialized array and the ID in database?

    Example:

    // ------------ STORING TO COOKIE AND DATABASE ------------ //
    $id = uniqid();
    setcookie("id", $id, time()+60*60*24); // 1 day
    
    $serialized = serialize($array);
    mysql_query("INSERT INTO yourTable (id, array) VALUES ('$id', '$serialized')");
    
    
    // ------------ SELECTING FROM DATABASE ------------ //
    if(!isset($_COOKIE['id'])) die();
    $id = mysql_real_escape_string($_COOKIE['id']);
    
    $result = mysql_query("SELECT array FROM yourTable WHERE id = $id LIMIT 1");
    if(!is_resource($result)) die();
    $serialized = mysql_result($result, 0);
    $array = unserialize($serialized);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store some data that is essentially just an array of key-value
I have this function, I need to store some values in an array, I
I need some help on figuring out a way to store my data that
I need an array to store some geometrical data. I would like to simply
I need to store an array of words and bytes (and some other data)
For my application I need to store some data in an array with the
I am creating a windows phone application, which need to store some data in
I want to store some data during my site viewing. Sometime i need to
I have some things in my app that I need to store, in order
I have some encrypted NSString store in a transformable field. I need to decrypt

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.