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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:15:05+00:00 2026-06-07T20:15:05+00:00

function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires

  • 0
function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

$(document).ready(function(){
alert(getCookie('foo'));
setCookie('foo','test'); //just setting a cookie on page load

$('#bing').click(function(){
$('#frm1').submit();

});
});



HTML side(foo.phtml)

<a href="javascript:void(0);" id="bing">Go</a>

<form id="frm1" method="POST" action="/somecontroller/someaction">
<input type="hidden" name="foo_post" value="this is from post" />
</form>

//server side

public function someactionAction(){

$_COOKIE['foo'] = $this->_request->getPost('foo_post');
$this->_redirect('/somecontroller/foo');
}

My problem is on the very first load of a page the alert returns null since cookie is not set and if i refresh again,ill get an alert “test” but if i click on the anchor tag a form submit will occur and the cookie value is rewritten as “this is from post”,so obviously after the action back to the page ill get an alert of “this is from post” ,BUT im still getting an alert “test” ,The cookie value is not getting rewritten

In my mozilla cookie console there are two cookies with the name foo with values “test” and “this is from post”

  • 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-07T20:15:06+00:00Added an answer on June 7, 2026 at 8:15 pm

    “there are two cookies with the name foo”

    If the name is identical, the domains must be different. Set both cookies using the same domain. Be aware that example.net is different from www.example.net or .example.net.

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

Sidebar

Related Questions

function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = createCustomURL(WinNetwork.UserName); document.getElementById(psyncLink).src =
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS= + WinNetwork.UserName;
Here is my code for setting a cookie: function setCookie(c_name, value, expiredays) { alert(setting
I use this function to set a cookie for the entire domain name: setcookie(tuittingID,
The getCookie function is first called in a checkCookie function as so: var username=getCookie(username);
function checkuser(user) { var ret = false; $.ajax({ type:'POST', url:'user.php', async:false, data:{'user':user}, success:function (data)
function cookiesToSession() { foreach($_COOKIE as $key => $value) { $_SESSION[$key] = $value; } }
function Person() {} Person.prototype.population = 0; Person.prototype.constructor = function(name) { this.name = name; console.log(Name:
function getUser() { FB.api('/me', function(response) { console.log('Response is '+response); alert('Your name is ' +

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.