Jump to content

Recommended Posts

Hello all,

 

I hope someone can help because I'm lost...

How do I delete a cookie that was created in a sub directory?

 

For insatnce I have www.mysite.co.uk/main_detail.php

a user navigates to www.mysite.co.uk/subdirectory/detail.php where a cookie is created. If they click on a link that returns them to www.mysite.co.uk/main_detail.php how do I delete the cookie creted on the sub directories page??

 

I have tried setcookie("detail_cookie",$detail_cookie, time()-60); on the main_detail.php page but it doesn't work.

 

I hope this made sense.

 

Many Thanks

Link to comment
https://forums.phpfreaks.com/topic/134980-solved-delete-cookie-from-sub-directory/
Share on other sites

You need to specify the cookie path in the set_cookie() path parameter

// set
setcookie("test", $value, time()+3600, "/mysubdir/");
// destroy
setcookie ("test", "", time() - 3600, "/mysubdir/");

 

If you set the path to / it will be available within the entire domain

setcookie("test", $value, time()+3600, "/");

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.