By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

cookies & sessions

100+
P: 110
I'm building a facebook app, and have been following the guidelines and posting on the facebook message board, but can't seem to get anywhere.


Facebook creates a session and cookie on the users machine for the facebook application. However, logging out of facebook, does not remove this session or cookie.

I'm using
Expand|Select|Wrap|Line Numbers
  1. require_once('../facebook.php');
  2. session_start();
  3.     setcookie(session_name(), '', time()-42000, '/');
  4.  
  5. session_destroy();
  6.  
to try to remove the session, but it looks like that is only removing the last entry of the cookie array (or params).

Any idea on how I can clear the entire cookie and session?
below is the code facebook uses to create the cookie. I've tried creating a function to recreate the cookie as empty, but no luck.

Expand|Select|Wrap|Line Numbers
  1. function logout_user($user, $session_key, $expires=-3600) {
  2.     if (!$this->in_fb_canvas() && (!isset($_COOKIE[$this->api_key . '_user'])
  3.                                    || $_COOKIE[$this->api_key . '_user'] != $user)) {
  4.       $cookies = array();
  5.       $cookies['user'] = $user;
  6.       $cookies['session_key'] = $session_key;
  7.       $sig = self::generate_sig($cookies, $this->secret);
  8.       foreach ($cookies as $name => $val) {
  9.         setcookie($this->api_key . '_' . $name, $val, (int)$expires);
  10.         $_COOKIE[$this->api_key . '_' . $name] = $val;
  11.       }
  12.       setcookie($this->api_key, $sig, (int)$expires);
  13.       $_COOKIE[$this->api_key] = $sig;
  14.     }
  15.     $this->user = $user;
  16.     $this->api_client->session_key = $session_key;
  17.   }
  18.  
Thanks
Pete
Jan 9 '08 #1
Share this Question
Share on Google+
1 Reply


stepterr
100+
P: 157
I'm building a facebook app, and have been following the guidelines and posting on the facebook message board, but can't seem to get anywhere.


Facebook creates a session and cookie on the users machine for the facebook application. However, logging out of facebook, does not remove this session or cookie.

I'm using
Expand|Select|Wrap|Line Numbers
  1. require_once('../facebook.php');
  2. session_start();
  3.     setcookie(session_name(), '', time()-42000, '/');
  4.  
  5. session_destroy();
  6.  
to try to remove the session, but it looks like that is only removing the last entry of the cookie array (or params).

Any idea on how I can clear the entire cookie and session?
below is the code facebook uses to create the cookie. I've tried creating a function to recreate the cookie as empty, but no luck.

Expand|Select|Wrap|Line Numbers
  1. function logout_user($user, $session_key, $expires=-3600) {
  2.     if (!$this->in_fb_canvas() && (!isset($_COOKIE[$this->api_key . '_user'])
  3.                                    || $_COOKIE[$this->api_key . '_user'] != $user)) {
  4.       $cookies = array();
  5.       $cookies['user'] = $user;
  6.       $cookies['session_key'] = $session_key;
  7.       $sig = self::generate_sig($cookies, $this->secret);
  8.       foreach ($cookies as $name => $val) {
  9.         setcookie($this->api_key . '_' . $name, $val, (int)$expires);
  10.         $_COOKIE[$this->api_key . '_' . $name] = $val;
  11.       }
  12.       setcookie($this->api_key, $sig, (int)$expires);
  13.       $_COOKIE[$this->api_key] = $sig;
  14.     }
  15.     $this->user = $user;
  16.     $this->api_client->session_key = $session_key;
  17.   }
  18.  
Thanks
Pete
This is what I use to clear my cookies.

[PHP]<?php
$past = time() - 100;
//this makes the time in the past to destroy the cookie
setcookie(ID_my_site, gone, $past);
setcookie(Key_my_site, gone, $past);
header("Location: login.php");
?>[/PHP]
Jan 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.