3
* Service Provider Example -- Logout
5
* Copyright (C) 2004 Entr'ouvert
6
* http://lasso.entrouvert.org
8
* Authors: Christophe Nowicki <cnowicki@easter-eggs.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
$config = unserialize(file_get_contents('config.inc'));
27
require_once 'DB.php';
29
if (!empty($_GET['SID']))
30
session_start($_GET['SID']);
34
if (!isset($_SESSION["nameidentifier"])) {
35
print "User is not logged in";
41
$db = &DB::connect($config['dsn']);
44
die($db->getMessage());
46
$server_dump = file_get_contents($config['server_dump_filename']);
48
$server = LassoServer::newfromdump($server_dump);
50
$logout = new LassoLogout($server, lassoProviderTypeSp);
52
$query = "SELECT identity_dump FROM users WHERE user_id='";
53
$query .= $_SESSION['user_id']."'";
55
$res =& $db->query($query);
57
if (DB::isError($res))
58
print $res->getMessage(). "\n";
60
$row = $res->fetchRow();
62
$logout->setIdentityFromDump($row[0]);
63
$logout->setSessionFromDump($_SESSION['session_dump']);
65
$logout->initRequest();
66
$logout->buildRequestMsg();
68
$url = parse_url($logout->msgUrl);
71
"POST %s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\nContent-Type: text/xml\r\n\r\n%s\r\n",
72
$url['path'], $url['host'], $url['port'],
73
strlen($logout->msgBody), $logout->msgBody);
75
# PHP 4.3.0 with OpenSSL support required
76
$fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno));
81
if (!preg_match("/^HTTP\/1\\.. 200/i", $ret)) {
82
die("User is already logged out");
86
$reponse .= @fread($fp, 8192);
91
# Destroy The PHP Session
101
header("Request-URI: $url");
102
header("Content-Location: $url");
103
header("Location: $url");