Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

problem with removing cookie

Featured Replies

hi guys,

I have a webpage that allows users to login and sign in automatically if they check the "sign me in" check box. I use cookie to store their username and they are automatically redirected to their profile by the username stored in cookie.

I want to remove this cookie when they click on logout button. this is my logout function which is triggered when the logout is clicked, but it does not remove cookie.

 

public function logoutAction()

{
session_start();
unset($_COOKIE['username']);
setcookie("username",' ',time()-10);
session_destroy();
header("location:/virtualsociety/register/stage1");
}

 

and this function is called through ajax call.

 

what is the problem? I guess because it is called through ajax in background with out involving browser.

 

tnx alot.

Edited by stallman3738

For 1 u dont need a session start or destroy for removing a cookie try this function

 

public function logoutAction()

{
       if(isset($_COOKIE['username'])):
        setcookie("username","",time()-3600);
        header("location:/virtualsociety/register/stage1");
exit;
else:
die('You are not logged in there for you cannot logout');
endif;
} 

basically what i tried us setting the time back further then just 10 normally u would set the time back atleast 3600 which is 1 hour

  • Author

For 1 u dont need a session start or destroy for removing a cookie try this function

 

public function logoutAction()

{
       if(isset($_COOKIE['username'])):
        setcookie("username","",time()-3600);
        header("location:/virtualsociety/register/stage1");
exit;
else:
die('You are not logged in there for you cannot logout');
endif;
} 

basically what i tried us setting the time back further then just 10 normally u would set the time back atleast 3600 which is 1 hour

 

I saw something very strange!

I change that function to this :

 

public function logoutAction()

{

header("location:/virtualsociety/registration/com/views/logout.php");

}

 

and this is logout.php page :

 

if(isset($_COOKIE['username']))

{

echo $_COOKIE['username'];

unset($_COOKIE['username']);

setcookie("username"," ",time()-3600*30*12);

exit();

}

else

{

echo "No cookie";

exit();

}

 

the output is No cookie but when I visit stage1 page, which is login page and has the following code, it outputs the cookie and redirects to profile !!!

session_start();

if(isset($_COOKIE['username']))

{

echo $_COOKIE['username'];

$dbuser = new \registration\com\models\database();

if($dbuser->autologin()==true) //checks if $_COOKIE['username'] corresponds to any existing user

header("location:/virtualsociety/home/viewProfile/".$_COOKIE['username']);

}

 

WHEN I CHECK THE BROWSER COOKIE, USERNAME IS STILL IN THERE WHILE PHP IN THIS CODE SAYS THERE IS NO COOKIE

 

print_r($_COOKIE);

 

THIS IS OUTPUT :

 

Array

(

[phpSESSID] => v7h79f2ajd4hi60apcu8qu6595

)

Edited by stallman3738

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.