Clear Cookies

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #24342

Hello again.

I am trying to make a button to clear all cookies (partner_id primery).
i used this code in a blank module (PHP enabled):

function deleteCookies()
{
if (isset($_SERVER)) {
$cookies = explode(';', $_SERVER);
foreach($cookies as $cookie) {

$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
echo '<script type="text/javascript">';
echo 'alert("Cookies Deleted!")';
echo '</script>';

}

echo '<input type="button" onClick="'.deleteCookies().'" value="Clear Cookie" /><br>';


but when i am runing it, it does not clear the most importent cookie, the partner_id..
So i am asking, can something close to this can be done to clear the partner_id cookie?

thanks alot.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 3 months ago #24350

You should use $_COOKIE directly in your foreach. But I don't think that it comes from that.
You code seems correct.

Maybe it's because you have partner_id somewhere which is set again automatically at some point after you delete it ?

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #24353

thanks for replay.
I checked again and both $_COOKIE and $_SERVER contains only the basic joomla cookies.. not login info,hikashop, languague or anything else (__utma,__utmb...), i guess because this is external page without joomla authentication.. (blank module display the same cookies with $_SERVER).

I elso cannot use $_COOKIE at the blank module because i cannot start session in there..

Any ideas?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 3 months ago #24356

Oh, I didn't saw the last line of code, but I can see that you're trying to call a php function with javascript. That's not possible. What you code does is that it calls the deleteCookies function on every page where you have the code and displays the alert box, regardless of whether you click on the button or not.
You would have to create a form and have a controller or at leadt a php page which would be called by the button where you would have your code.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 2
13 years 3 months ago #24360

Ok now i know why that happened.. thanks :)

I cant use form because i need link that will do the clearing (unvisible link), although i changed to form to see and it is working, but still the cookies that are being cleaned are the basics, and not hikashop_affiliate..

I got no ideas what to do, so i can see all of my website cookies...

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 3 months ago #24363

You should create a component/controller/task, or a plugin or a module in joomla in order to have the session activated for your code then.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum