473,657 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookies & sessions

110 New Member
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 3084
stepterr
157 New Member
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_m y_site, gone, $past);
header("Locatio n: login.php");
?>[/PHP]
Jan 20 '08 #2

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

Similar topics

3
5887
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 availible. What I'm trying to get is this: 1) Variable(A) passed from HTML page to script. 2) Script checks for cookie.
5
3183
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 off, the global variables are empty between pages, fine, that tells me cookies store the global variables - right? I store the values in $_session and when cookies are turned on values are passed between web pages - I can see these values in fields...
1
2810
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 missing the big picture. Is it like this: 1. user comes to site 2. user does something (e.g. a search) that may be useful later => session
2
3336
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 the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i don;t know how to do it?
2
1685
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 for users with a username and password. The site is mainly ASP based. The webserver is an IIS6 and I do NOT have access to server settings (session timeout, security,...).
7
2001
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 every session tutorial I have ever read, the author invariably mentions the 2 main ways of propagating sessions - through cookies and appended to the URL. The author also almost always talks about the method being dependent on the user's...
7
3331
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 is valid. It seems that these information are valid until the browser closes. On the other hand it's possible to set expiration time for cookies. Does this mean that I have to abanbon $_SESSION altogether and switch to
5
5559
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 Explorer. I would appreciate any help anyone can offer, please. First, consider the following very simple JavaScript function: function CookiesEnabled() { SetCookie( "testcookie", "testcookie" ) ; var bCookiesEnabled = ( GetCookie(...
8
2752
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* image requests to a Php script that checks for that variable before simply delivering the image. Direct links to my images will fail this test and no image is served. I am monitoring my script by sending emails to myself and finding that...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.