Jump to content

[SOLVED] Can't remove cookies on logout.


Scooby08

Recommended Posts

I have a simple user/login with remember me feature and everything seems to work except for when I log it, I believe it is supposed to remove the cookies, but I'm really not too sure if that is correct..  Need advice..

 

I create the cookies like so:

 

<?php
setcookie("TestCookie[txt_user_name]", $txt_user_name, time() + 3600);
setcookie("TestCookie[txt_user_password]", $txt_user_password, time() + 3600);
?>

 

My cookies array is like so:

 

Array
(
    [TestCookie] => Array
        (
            [txt_user_name] => admin
            [txt_user_password] => admin
        )

    [phpSESSID] => 04m88l0st6c327njr3apu4fa16
)

 

Then for my logout code I am using this code:

 

<?php
session_unset();
session_destroy();

if (isset($_COOKIE['TestCookie'])) {
$time = time();
setcookie("TestCookie[txt_user_name]", $time - 3600);
setcookie("TestCookie[txt_user_password]", $time - 3600);
}
?>

 

Is this correct?? And if so, what is supposed to be happening?? I would assume that if I logged out I would then be directed to the login form, but this is not happening.. It always stays logged in..

Link to comment
Share on other sites

try this. TestCookie[txt_user_name] is a variable right?

 

etcookie(TestCookie[txt_user_name], $txt_user_name, time() + 3600);
setcookie(TestCookie[txt_user_password], $txt_user_password, time() + 3600);
[code]
[code]
setcookie(TestCookie[txt_user_name],"", $time - 3600);
setcookie(TestCookie[txt_user_password],"", $time - 3600);
[code]

[/code][/code][/code]

Link to comment
Share on other sites

missing '$' sign

 

setcookie($TestCookie[txt_user_name], $txt_user_name, time() + 3600);
setcookie($TestCookie[txt_user_password], $txt_user_password, time() + 3600);

and 

setcookie($TestCookie[txt_user_name],"", $time - 3600);
setcookie($TestCookie[txt_user_password],"", $time - 3600);

Link to comment
Share on other sites

Well I finally got something to work.. I had to add a slash and my domain name to the cookies like so:

 

<?php
/*SET COOKIE*/
setcookie("TestCookie[txt_user_name]", $txt_user_name, time() + 3600, "/", "domain_name.com");
setcookie("TestCookie[txt_user_password]", $txt_user_password, time() + 3600, "/", "domain_name.com");

/*EXPIRE COOKIE*/
setcookie("TestCookie[txt_user_name]", "", time() - 3600, "/", "domain_name.com");
setcookie("TestCookie[txt_user_password]", "", time() - 3600, "/", "domain_name.com");
?>

Link to comment
Share on other sites

Relying on deleting cookies or deleting the session id cookie to log someone out is pointless and is a waste of processor time and bandwidth to delete them. Anyone can make a copy of a cookie and put it back after you delete it.

 

To log someone out, you should only rely on data stored on your server, such as a "logged in" column in your user table in a database.

Link to comment
Share on other sites

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.