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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:12:59+00:00 2026-05-16T21:12:59+00:00

I set the cookies regularly in a callback page in my Twitter application. Everything

  • 0

I set the cookies regularly in a callback page in my Twitter application. Everything works fine.

Now, using jQuery, I submit a form, and the callback function activates a PHP script. That script only needs to set one cookie to the serialized values of $_POST; and the values run fine (both serialized and normal, I echoed them out to debug). The expiration time is set to 1 year ahead. But for some reason, the cookie just won’t appear anywhere. Here’s the code:

// js/main.js
$('#settings-form').live('submit', function() {
    $.post('controllers/settings.php', $(this).serialize(), function(data) { // Everything here works.
        if (data == 'OK') // no errors spits out "OK". this works
            changeView({'msg': 'Your settings were saved successfully.'}); // This just resets the view and adds a message div at the top. This works
        else
            changeView({'msg': data}); // This echoes the error if any exists. Doesn't happen, no errors arise
    });
    return false; // Cancels redirecting after submitting form
});
// controllers/settings.php
setcookie('user_settings', serialize($_POST), strtotime('+1 year'));

I checked all the variables and I even tried setting dummy ones for test (like “boo” instead of serialize($_POST). for some reason that doesn’t work.

Any ideas why this is happening? I tried doing a chdir(‘..’); to make the cookie dir go to the right place, but that doesn’t seem to be the problem, checking the cookies inside my browser doesn’t seem to work at all, for any path. It just doesn’t work at all. I also just tried manually changing the domain and path, but those don’t work either.

  • 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-16T21:13:00+00:00Added an answer on May 16, 2026 at 9:13 pm

    Firstly, the chdir() thing is a red-herring — Cookies are domain-specific; the directory path doesn’t have any bearing on them.

    Cookies can work a bit strangely when you’re making ajax type calls, and I think this is what you’re seeing — The server is probably setting the cookie, but the browser may not be setting it in the cookies data it as it’s not a page load.

    I would suggest you’d be better off using PHP’s session handling rather than cookies; it’s better for security, less bandwidth (because the whole of the cookie data is transmitted in both directions with every http single request), and more likely to work.

    If you really want to use cookies, it may work better if you use Javascript to do it. You can set cookies in your javascript code by accessing document.cookie. (you need to get the syntax right for the cookie string, but JQuery probably has its own functions that makes them easier to work with)

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

Sidebar

Related Questions

I am using a jQuery plugin to set cookies and when I use localhost
I have an application on appspot that works fine through regular browser, however when
i need to set cookies in my page, but it returns Warning: Cannot modify
I am not able to set cookies using following statements self.request.headers['Cookie'] = 'uniqueid =
How can I set the cookies in my PHP apps as HttpOnly cookies ?
I need to set/get the cookies stored at first.example while browsing second.example , I
Inspired by this CodingHorror article, Protecting Your Cookies: HttpOnly How do you set this
I set up a website to use SqlMembershipProvider as written on this page .
I set cookies based on the referral links and they all start with the
How can I set cookies in PHP server-side with Ajax and read cookies in

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.