473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

cookies & sessions

110 100+
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
1 3063
stepterr
157 100+
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

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

Similar topics

3
by: Daniel Ruscoe | last post by:
Hi chaps, I'm relatively new to the language, but I want to create a simple order form using PHP and cookies. Please let me know if there's a better way in this situation, database isn't...
5
by: TG | last post by:
This is more of a pain than I thought it would be. I need a simple code segment to determine whether a browser accepts cookies or not. When I pass variables between pages when cookies are turned...
1
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
2
by: Ik Ben Het | last post by:
Hello, I posted a simular question in the "IIS Security" group but it think it is more usefull to post it here. I want to do something very simpel. Make a part of my website available only...
7
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in...
7
by: Atte André Jensen | last post by:
Hi I'm developing a site where I'd like to store information during a users visit. So far I've been using sessions, but as far as I can tell it's not possible to control for how long a session...
5
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
8
by: Chuck Anderson | last post by:
I've instituted a sessions based scheme on my web site to combat hot linking to my images. When someone requests a page at my site, I set a session variable. I then use htaccess to redirect *all*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.