Jump to content

[SOLVED] Delete cookie from sub directory


New Coder

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, "/");

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.