/    Sign up×
Community /Pin to ProfileBookmark

clearing cookies

Hi everyone,

I am having trouble editing existing cookies on my web page. I have been googling this for a while now an tried many different javascript functions (given that I’m not well versed in javascript) but with no luck.

The webpage is on a content manager that builds the pages in ajax but not sure where or how it is creating the cookie. Currently there are 2 particular cookies that it creates and has an expiration date of 4 years from the time it creates it. I desperately need to change the expiration date or clear it when it goes to a particular page when it loads. I’ve found the cookies that have been giving me problems which are named ‘cid’ and ‘shopOrder’. These cookies are giving me problems. Any help would be appreciated.

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinOct 27.2009 — We really need to see the cookie script.
Copy linkTweet thisAlerts:
@akirajubeiauthorOct 27.2009 — This is what I have tried. I needed 2 cookies so I just duplicated everything. Don't think this is the right way but seems to be doing something right.

<script language="javascript" type="text/javascript">


function Get_Cookie( check_name ) {

var a_all_cookies = document.cookie.split( ';' );

var a_temp_cookie = '';

var cookie_name = '';

var cookie_value = '';

var b_cookie_found = false; // set boolean t/f default f

for ( i = 0; i < a_all_cookies.length; i++ )
{
a_temp_cookie = a_all_cookies[i].split( '=' );


tShopOrderID = a_temp_cookie[0].replace(/^s+|s+$/g, '');
cid= a_temp_cookie[0].replace(/^s+|s+$/g, '');

// if the extracted name matches passed check_name
if ( tShopOrderID == check_name )
{
b_cookie_found = true;
// we need to handle case where cookie has no value but exists (no = sign, that is):
if ( a_temp_cookie.length > 1 )
{
cookie_value = unescape( a_temp_cookie[1].replace(/^s+|s+$/g, '') );
}
// note that in cases where cookie is initialized but no value, null is returned
return cookie_value;
break;
}
a_temp_cookie = null;
tShopOrderID = '';
if ( cid == check_name )
{
b_cookie_found = true;
// we need to handle case where cookie has no value but exists (no = sign, that is):
if ( a_temp_cookie.length > 1 )
{
cookie_value = unescape( a_temp_cookie[1].replace(/^s+|s+$/g, '') );
}
// note that in cases where cookie is initialized but no value, null is returned
return cookie_value;
break;
}
a_temp_cookie = null;
cid = '';

}
if ( !b_cookie_found )
{
return null;
}

}

function Set_Cookie( name, value, expires, path, domain, secure ) {

// set time, it's in milliseconds

var today = new Date();

today.setTime( today.getTime() );

// if the expires variable is set, make the correct expires time, the

// current script below will set it for x number of days, to make it

// for hours, delete * 24, for minutes, delete * 60 * 24

if ( expires )

{

expires = expires *
1000 * 60 * 60 * 24;

}

//alert( 'today ' + today.toGMTString() );// this is for testing purpose only

var expires_date = new Date( today.getTime() + (expires) );

//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );

}

// this deletes the cookie when called

function Delete_Cookie( name, path, domain ) {

if ( Get_Cookie( tShopOrderID ) ) document.cookie = name + "=" +

( ( path ) ? ";path=" + path : "") +

( ( domain ) ? ";domain=" + domain : "" ) +

";expires=Thu, 01-Jan-1970 00:00:01 GMT";

}

function Delete_Cookie2( name, path, domain ) {

if ( Get_Cookie( cid ) ) document.cookie = name + "=" +

( ( path ) ? ";path=" + path : "") +

( ( domain ) ? ";domain=" + domain : "" ) +

";expires=Thu, 01-Jan-1970 00:00:01 GMT";

}

</script>

<script type="text/javascript">

// remember, these are the possible parameters for Set_Cookie:

// name, value, expires, path, domain, secure

Set_Cookie( 'tShopOrderID', 'null', '', '/', '.domain.com', '' );

Set_Cookie( 'cid', 'null', '', '/', '.domain.com', '' );

// and these are the parameters for Delete_Cookie:

// name, path, domain

// make sure you use the same parameters in Set and Delete Cookie.

Delete_Cookie('tShopOrderID', '/', '.domain.com');

( Get_Cookie( 'tShopOrderID' ) )

Delete_Cookie2('cid', '/', '.domain.com');

( Get_Cookie( 'cid' ) )

</script>
Copy linkTweet thisAlerts:
@justinbarneskinOct 28.2009 — The trouble may be in the path. Wherever the cookie was created, you may need to delete the cookie there. This might mean creating a folder if it no longer exists, and placing a simple file there to call the [B]two[/B] Delete_Cookie functions
×

Success!

Help @akirajubei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...