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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:22:41+00:00 2026-05-20T10:22:41+00:00

I need to store some data in a cookie. The data goes through mcrypt

  • 0

I need to store some data in a cookie. The data goes through mcrypt encryption and then base64 to prevent any strange characters being used.
Storing the encrypted & encoded string in a session and reading it back & decrypting/decoding works perfectly. Doing the same to a cookie fails – completely gibberish text is returned.

Obviously this is due to the fact that the mcrypt-decrypt function call receives improper data, making me to believe that the contents of my cookie are affected in one way or another.

What on earth is PHP doing behind the scenes to my cookie data?

Code:
(Note that the mcrypt-functions are represented below as plain function call for readability )

$string = base64_encode( mcrypt_encrypt( 'A string' ) );
setcookie('string', $string, time()+3600);
$_SESSION['string'] = $string;

$sessiondata = base64_decode( mcrypt_decrypt($_SESSION['string']); // A string!
$cookiedata = base64_decode( mcrypt_decrypt($_COOKIE['string']) ); // Completely gibberish
  • 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-20T10:22:42+00:00Added an answer on May 20, 2026 at 10:22 am

    Try calling urlencode() on your string before sending it to the cookie — I seem to recall that PHP automatically does a urldecode() on the data when making it available in $_COOKIE.

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

Sidebar

Related Questions

No related questions found

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.